将Spring Batch与JtaTransactionManager一起使用时出现java.lang.StackOverflowError错误

问题描述 投票:2回答:1

我正在尝试将JtaTransactionManager与Spring Batch一起使用。

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();
}

以及如何从石英调度程序作业启动作业:

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时,它会抛出StackOverFlowError,看起来错误是一个无限循环。

[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) ~[?:?]

直到最后:

    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:?]
  • 事务正在使用AspectJ编译时编织

@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)

  • 使用相同的事务时,依赖项目没有问题
  • 错误只发生在我正在处理的项目中。

有人可以帮我指出可能导致问题的原因吗?谢谢。

spring-batch stack-overflow jta transactionmanager
1个回答
1
投票

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

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

在配置批处理配置器之前,通过@EnableBatchProcessing proccess解决了我的错误。所以只需将@EnableBatchProcessing放在为我工作的转轮上。

希望能帮助到你。

© www.soinside.com 2019 - 2024. All rights reserved.