Tag: spring

Spring Batch Partitioning在itemReader中注入stepExecutionContext参数

我正在尝试使用Partitioner学习Spring Batch。 问题是我需要从Partitioner实现动态设置文件名。 我试图在itemReader获取它。 但它给出了文件名null 。 我的Spring Batch配置: @Bean @StepScope public ItemReader itemReader(@Value(“#{stepExecutionContext[filename]}”) String filename) throws UnexpectedInputException, ParseException { FlatFileItemReader reader = new FlatFileItemReader(); DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(); String[] tokens = { “username”, “userid”, “transactiondate”, “amount” }; tokenizer.setNames(tokens); reader.setResource(new ClassPathResource( “input/”+filename)); DefaultLineMapper lineMapper = new DefaultLineMapper(); lineMapper.setLineTokenizer(tokenizer); lineMapper.setFieldSetMapper(new RecordFieldSetMapper()); reader.setLinesToSkip(1); reader.setLineMapper(lineMapper); return reader; } […]

Java Spring Boot Restcontroller RequestMapping执行了两次

我有一个带有RestController的Spring Boot应用程序和一个下载并传递图像的方法: @RestController public class PictureController { @RequestMapping(“/picture/{id}”) public HttpEntity getImage(@PathVariable String id) { logger.info(“Requested picture : >> ” + id + ” <<"); // !! Execute code for downloading !! // Create Headers… // return HttpEntity } } 在日志文件中,我可以读到该方法执行两次 ,我不知道为什么。 如果我删除下载代码,它会按预期执行一次 。 是因为下载需要一秒钟吗? 下载代码是…… byte[] response; try { URL url = new URL(….); InputStream […]

如何在Spring启动中实现循环队列使用者

我正在构建一个消息驱动的服务,它将在一个集群中运行,需要以循环方式从RabbitMQ队列中提取消息。 该实现目前正在逐步将消息从队列中拉出,导致一些服务器得到备份而其他服务器处于空闲状态。 当前的QueueConsumerConfiguration.java如下所示: @Configuration public class QueueConsumerConfiguration extends RabbitMqConfiguration { private Logger LOG = LoggerFactory.getLogger(QueueConsumerConfiguration.class); private static final int DEFAULT_CONSUMERS=2; @Value(“${eventservice.inbound}”) protected String inboudEventQueue; @Value(“${eventservice.consumers}”) protected int queueConsumers; @Autowired private EventHandler eventtHandler; @Bean public RabbitTemplate rabbitTemplate() { RabbitTemplate template = new RabbitTemplate(connectionFactory()); template.setRoutingKey(this.inboudEventQueue); template.setQueue(this.inboudEventQueue); template.setMessageConverter(jsonMessageConverter()); return template; } @Bean public Queue inboudEventQueue() { return new […]

无法在数据库中保存clob数据类型(Struts,Spring,Hibernate)

@Column(name=”transpired”) @Lob private String transpired; public String getTranspired() { return transpired; } public void setTranspired(String transpired) { this.transpired = transpired; } 我尝试在我们的模型类中使用以下代码。 “透明”是一个包含长文本消息(报告)的字段。 查看“报告”时,它会从数据库中检索数据并在我们的UI中正确显示。 但是,当我保存(编辑或创建)报表时,数据库上的字段保存为(null)。 关于如何保存长文本的任何想法? 我们之前使用的是varchar2(4000),但大多数报告都超过4000个字符。 谢谢。 编辑:我正在使用Oracle 10g。 列类型是CLOB。

使用Spring + Hibernate / EntityManager时遇到BeanCreationException

关于我的post/问题“使用SpringFramework , EntityManager总是为NULL” , 我在这部分代码中遇到以下exception: ApplicationContext appContext = new ClassPathXmlApplicationContext(“applicationContext.xml”); 线程“main”中的exceptionorg.springframework.beans.factory.BeanCreationException:创建名为’tblFileinfoHome’的bean时出错:持久性字段的注入失败; 嵌套exception是org.springframework.beans.factory.BeanCreationException:创建在类路径资源[applicationContext.xml]中定义名称为’entityManagerFactory’的bean时出错:init方法的调用失败; 嵌套exception是java.lang.AbstractMethodError:org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getValidationMode()Ljavax / persistence / ValidationMode; 以下是与我的Spring + Hibernate项目相关的文件 org.hibernate.ejb.HibernatePersistence com.msh.TblFileinfo <!– –> <!– –> <!– –> package com.msh; public class MavenSpringHibernate { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ApplicationContext appContext = new ClassPathXmlApplicationContext(“applicationContext.xml”); […]

弹簧控制器中的圆形视图

我正在尝试在Spring控制器中提供静态资源。 我有一个index.html文件,应该返回给每个请求。 我的控制器是: @Controller public class IndexController { @RequestMapping(value = “/**”, method = RequestMethod.GET) public String index() { return “index.html”; } } 我还添加了资源处理程序: @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler(“/**”).addResourceLocations(“classpath:/”); } 但最后我有以下exception: 圆形视图路径[/index.html]:将再次调度回当前处理程序URL [/index.html]。 检查您的ViewResolver设置! (提示:由于生成默认视图名称,这可能是未指定视图的结果。) 我明白,在我的配置中,所有请求都将由我的Spring控制器处理。 因此,当我请求,例如http://localhost/someText ,该请求将与我的控制器一起处理,然后我的控制器发送重定向到//localhost/index.html ,此请求转到Spring的DispatcherServlet然后重定向到我的再次控制器,导致上面的exception。 此外,我已经尝试了一些选项:制作网页filter,将我的请求处理到/index.html而不是通过spring servlet,但是通过默认的(在我的情况下是默认的服务器的默认服务),但是这是不可能的,因为我的应用程序不是打包为war,我的index.html文件位于/src/java/resources 。 实际上我发现,对我来说主要的问题是在我的请求的Spring的DispatcherServlet处理程序( //localhost/index.html )被检测为我的控制器,而不是资源处理程序。 protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { for (HandlerMapping […]

在LDAP中实现超时

我一直在处理我们使用LDAP获取用户详细信息的应用程序。 有时需要更多时间来获取用户详细信息。 我想在获取详细信息的方法上实现超时 ,以便在最坏的情况下我们可以避免在服务器中挂起事务。 这里我们使用LdapUtil类,我们在其中配置了LdapTemplate类来获取所需的详细信息。 我们如何在LDAP方法上实现超时? (在本例中为ldapTemplate.search(…)方法) public class LdapUtil { @Autowired(required = true) @Qualifier(value = “ldapTemplateApp”) LdapTemplate ldapTemplate; public Set findProducts(String UserId) { final Set products = newHashSet(); // Lookup the user String usrFilter = String.format(USERID_FILTER, globalUserId); ldapTemplate.search(“ou=Members”, usrFilter, // note this line new NameClassPairCallbackHandler() { public void handleNameClassPair(NameClassPair nameClassPair) { SearchResult result = […]

通知通道关闭到实现org.springframework.amqp.rabbit.connection.ConnectionListener的类

我们使用Spring-AMQP提供的ConnectionListener接口在底层连接上保留一个选项卡。 通过自动恢复创建通道,心跳设置为10分钟(针对某些产品需求)。 我的观察是即使在底层的rabbitMQ死后,connectionListener.onClose()方法也不会被调用近10分钟。 我们还对API执行运行状况检查,并使用connectionListener.isOpen()方法确定连接的状态。 并且因为SimpleConnection类中的这个代码块 @Override public boolean isOpen() { return delegate != null && (delegate.isOpen() || this.delegate.getClass().getSimpleName().contains(“AutorecoveringConnection”)); } 当连接自动恢复时,始终返回true。 因为Health API在连接中断后10分钟内没有得知连接失败。 是否有任何建议的方法来通知ConnectionListener通道关闭,因为isOpen方法显然无法满足需求? 正在实现ShutDownlistener的方式吗? 由于我们没有访问connectionListerner中的通道而无法直接执行connection.addConnectionListerner(this)。 从connectionFactory shutdownCompleted方法是否可以调用onClose或connectionListener上的任何其他方法来通知它关闭? 还有其他想法吗?

AngularJS中的文件上载JSON Spring MVC应用程序400错误请求所需的请求部分不存在

我们使用的是AngularJS 1.5.8,Spring 3.2.17,Jackson 2.6.7; 我们需要使用JSON DTO对象实现文件上传。 我们无法看到使用多种配置和方法的文件上传成功,单独的DTO作为json请求参数工作正常。 提前致谢! bill_payment.html的片段 app.js var app = angular.module(‘app’, [ ‘ngRoute’, ‘ngResource’, ‘billPaymentAppControllers’, ‘billPaymentAppServices’ ]); … app.directive(‘fileModel’, [‘$parse’, function ($parse) { return { restrict: ‘A’, link: function(scope, element, attrs) { var model = $parse(attrs.fileModel); var modelSetter = model.assign; element.bind(‘change’, function(){ scope.$apply(function(){ modelSetter(scope, element[0].files[0]); }); }); } }; }]); billPaymentControllers.js var […]

Java Hibernate json无限递归与自引用类

class级员工: @Entity @Table(name = “Employee”) public class Employee { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = “EmployeeID”) private int EmployeeID; @Column(name = “ManagerID”) private Integer ManagerID; @ManyToOne(cascade={CascadeType.ALL}) @JoinColumn(name=”ManagerID”, insertable = false, updatable = false) @JsonBackReference private Employee manager; @OneToMany(mappedBy=”manager”) @JsonManagedReference private Set employees; @ManyToOne(cascade={CascadeType.ALL}) @JoinColumn(name = “DepartmentID”) private Department department; @ManyToOne(cascade={CascadeType.ALL}) @JoinColumn(name = “SalaryTypeID”) private SalaryType […]