bal*_*teo 6 distributed-transactions spring-batch spring-boot spring-cloud-task
我正在尝试为配置了spring boot的spring batch/spring cloud任务应用程序配置XA /分布式事务.
我添加了以下依赖项,希望依赖spring boot auto配置:
compile("org.springframework.boot:spring-boot-starter-jta-atomikos")
Run Code Online (Sandbox Code Playgroud)
但是,以下两个类会导致配置两个事务管理器:
org.springframework.cloud.task.configuration.SimpleTaskConfiguration
org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration
请参阅以下消息:
2016-07-18 21:46:19.952 INFO 18995 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'transactionManager' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.cloud.task.configuration.SimpleTaskConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in org.springframework.cloud.task.configuration.SimpleTaskConfiguration]
Run Code Online (Sandbox Code Playgroud)
然后因为配置了PlatformTransactionManager命名transactionManager,我的atomikos自动配置没有被选中:
AtomikosJtaConfiguration did not match
- @ConditionalOnClass classes found: org.springframework.transaction.jta.JtaTransactionManager,com.atomikos.icatch.jta.UserTransactionManager (OnClassCondition)
- @ConditionalOnMissingBean (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) found the following [transactionManager] (OnBeanCondition)
Run Code Online (Sandbox Code Playgroud)
有人可以帮我防止transactionManager上面这两个类引起的过度强制吗?
查看您的示例后,我可以告诉您的是 - 没有办法使自动配置工作 - 即使您禁用事务管理的自动配置(您确实尝试过),任务和批处理自动配置(由@EnableBatchProcessing和@EnableTask) 仍然会注册自己的事务管理器,从而阻止 Atomikos 配置被触发。这样做的原因是因为@EnableBatchProcessing包含BatchConfigurationSelector配置类,而配置类又包含其中一个SimpleBatchConfiguration或ModularBatchConfiguration两个,并且它们都将始终注册事务管理器 - 任何一个 bean 定义上都没有条件注释。@EnableTask做了非常相似的事情,只是与SimpleTaskConfiguration.
因此,我认为解决这个问题的唯一方法是完全手动创建批处理和任务配置。
至于如何手动配置批处理和任务,我建议查看SimpleTaskConfiguration和AbstractBatchConfiguration - 您可以在那里看到您需要注册的所有 bean。
或者,您可以在此 Java Code Geeks 页面上查看批处理示例,您只需将 XML 配置转换为 Java 配置即可。
| 归档时间: |
|
| 查看次数: |
1782 次 |
| 最近记录: |