Spring batch 将Spring批处理与JtaTransactionManager一起使用时出现java.lang.StackOverflower错误

Spring batch 将Spring批处理与JtaTransactionManager一起使用时出现java.lang.StackOverflower错误,spring-batch,stack-overflow,jta,transactionmanager,Spring Batch,Stack Overflow,Jta,Transactionmanager,我正在尝试将JtaTransactionManager用于Spring批处理 transactionManager是在依赖项项目中定义的Jta事务管理器 这是我的Spring批处理配置: @Configuration @EnableBatchProcessing public class IntegrationJobConfig implements BatchConfigurer { @Inject private JobBuilderFactory jobs; @Inject priva

我正在尝试将JtaTransactionManager用于Spring批处理

transactionManager是在依赖项项目中定义的Jta事务管理器

这是我的Spring批处理配置:

@Configuration
@EnableBatchProcessing
public class IntegrationJobConfig implements BatchConfigurer {

@Inject
private JobBuilderFactory jobs;

@Inject
private StepBuilderFactory stepBuilderFactory;

@Inject
private DataSource dataSource;

@Inject
private PlatformTransactionManager transactionManager;

@Override
public PlatformTransactionManager getTransactionManager() {
    return transactionManager;
}

@Override
public JobRepository getJobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setDataSource(dataSource);
    factory.setTransactionManager(getTransactionManager());
    factory.afterPropertiesSet();
    return  factory.getObject();
}

@Override
public JobLauncher getJobLauncher() throws Exception {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(getJobRepository());
    jobLauncher.afterPropertiesSet();
    return jobLauncher;
}

@Override
public JobExplorer getJobExplorer() throws Exception {
    JobExplorerFactoryBean jobExplorer = new JobExplorerFactoryBean();
    jobExplorer.setDataSource(dataSource);
    jobExplorer.afterPropertiesSet();
    return jobExplorer.getObject();
}
下面是我如何从quartz scheduler作业启动作业:

public class IncomingIntegrationJob extends QuartzJobBean {

@Inject
private JobLauncher jobLauncher;

@Inject
private Job myJob;

 @Override
 protected void executeInternal(JobExecutionContext context) {

  JobParametersBuilder builder = new JobParametersBuilder();
  builder.addDate("execDate", new Date());

  JobExecution result = jobLauncher.run(myJob, builder.toJobParameters());

 }
}
但当我启动上面的jobLauncher时,它抛出StackOverflowerError,似乎错误是一个无限循环

[m2016-06-12 14:58:00,108 INFO  [smrp-scheduler_Worker-1] [32morg.springframework.batch.core.repository.support.JobRepositoryFactoryBean No database type set, using meta data indicating: H2
[m2016-06-12 14:58:00,420 INFO  [smrp-scheduler_Worker-1] [32morg.springframework.batch.core.repository.support.JobRepositoryFactoryBean No database type set, using meta data indicating: H2
[m2016-06-12 14:58:00,423 INFO  [smrp-scheduler_Worker-1] [32morg.springframework.batch.core.launch.support.SimpleJobLauncher No TaskExecutor has been set, defaulting to synchronous executor.
[m2016-06-12 14:58:00,551 ERROR [smrp-scheduler_Worker-1] [1;31morg.quartz.core.JobRunShell Job inbound-batch-group.inbound-batch-job threw an unhandled Exception: 
java.lang.StackOverflowError
at java.lang.reflect.Method.hashCode(Method.java:331) ~[?:1.8.0_91]
at org.springframework.aop.framework.AdvisedSupport$MethodCacheKey.<init>(AdvisedSupport.java:597) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.AdvisedSupport.getInterceptorsAndDynamicInterceptionAdvice(AdvisedSupport.java:486) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:193) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at com.sun.proxy.$Proxy250.getTransaction(Unknown Source) ~[?:?]
at sun.reflect.GeneratedMethodAccessor182.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at com.sun.proxy.$Proxy250.getTransaction(Unknown Source) ~[?:?]
at sun.reflect.GeneratedMethodAccessor182.invoke(Unknown Source) ~[?:?]
  • 事务正在使用AspectJ编译时间编织
@启用事务管理(mode=AdviceMode.ASPECTJ)

  • 使用同一事务时,依赖项项目没有问题
  • 错误只发生在我正在处理的项目中
有人能帮我指出问题的原因吗?
谢谢。

我知道已经有一段时间了,但是在将spring boot迁移到版本2时,我遇到了同样的问题

如果我们需要在批处理和应用程序中的其他模块中使用相同的事务管理器,我们将覆盖批处理配置器和事务管理器

在我的例子中,通过在配置批处理配置器之前使用@EnableBatchProcessing进程解决了该错误。所以只要在运行程序上添加@EnableBatchProcessing就可以了


希望有帮助。

当你说“事务正在使用AspectJ编译时间编织”时,你是什么意思?Spring Batch显式处理事务,因此添加您自己的事务语义(例如通过
@Transactional
)通常会导致问题。您是否对其进行过排序?@MichaelMinella:我也有类似的问题。这是我的问题。spring jobLauncher.run有点可疑。如有任何见解,将不胜感激。
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at com.sun.proxy.$Proxy250.getTransaction(Unknown Source) ~[?:?]
at sun.reflect.GeneratedMethodAccessor182.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
Wrapped by: org.quartz.SchedulerException: Job threw an unhandled exception.
at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [quartz-2.2.3.jar:?]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.3.jar:?]