我正在尝试将 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)
- 使用同一事务时,依赖项项目没有问题
- 该错误仅发生在我正在处理的项目中。
任何人都可以帮助我指出可能导致问题的原因?谢谢你。