我想讓Atomikos與我的Spring Boot/Spring批處理應用程序一起工作。在Spring Boot/Spring批處理應用程序上配置Atomikos問題
這裏是我的代碼的相關部分:
數據源配置:
@Configuration
public class DatasourceConfiguration extends AbstractCloudConfig {
@Bean
@Qualifier("batch_database")
public DataSource batchDatasource() {
return connectionFactory().dataSource("batch_database");
}
@Bean
public PlatformTransactionManager transactionManager(){
return new JtaTransactionManager();
}
@Bean
public TaskConfigurer configurer(){
return new DefaultTaskConfigurer(batchDatasource());
}
}
Atomikos公司自動配置依賴性:
compile("org.springframework.boot:spring-boot-starter-jta-atomikos")
我application.properties
:
spring.datasource.application.driver-class-name=org.postgresql.xa.PGXADataSource
spring.datasource.batch.driver-class-name=org.postgresql.xa.PGXADataSource
下面是自動配置報告:
DataSourceTransactionManagerAutoConfiguration matched
- @ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition)
DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration matched
- @ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) found the following [batchDatasource, applicationDatasource, batch_database, application_database, database] (OnBeanCondition)
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)
AtomikosJtaConfiguration.AtomikosJtaJmsConfiguration did not match
- required @ConditionalOnClass classes not found: javax.jms.Message (OnClassCondition)
- Ancestor 'org.springframework.boot.autoconfigure.transaction.jta.AtomikosJtaConfiguration' did not match (ConditionEvaluationReport.AncestorsMatchedCondition)
我不知道爲什麼Atomikos公司是不是自動配置...任何人都可以請幫助?
編輯:我註釋掉中的JTA TransactionManager豆,我現在得到以下自動配置報告:
DataSourceTransactionManagerAutoConfiguration matched
- @ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition)
DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration matched
- @ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) found the following [batchDatasource, applicationDatasource, batch_database, application_database, database] (OnBeanCondition)
TransactionAutoConfiguration matched
- @ConditionalOnClass classes found: org.springframework.transaction.support.TransactionTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition)
- @ConditionalOnSingleCandidate (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) found a primary candidate amongst the following [transactionManager] (OnBeanCondition)
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)
AtomikosJtaConfiguration.AtomikosJtaJmsConfiguration did not match
- required @ConditionalOnClass classes not found: javax.jms.Message (OnClassCondition)
- Ancestor 'org.springframework.boot.autoconfigure.transaction.jta.AtomikosJtaConfiguration' did not match (ConditionEvaluationReport.AncestorsMatchedCondition)
我怎樣才能確保Atomikos公司事務管理器拾取?
編輯2:我已經排除TransactionManager
類如下:
@EnableAutoConfiguration(exclude = {DataSourceTransactionManagerAutoConfiguration.class, TransactionAutoConfiguration.class})
,但我似乎SimpleBatchConfiguration
和SimpleTaskConfiguration
仍然迫使一些TransactionManager
類(ES)的一個對我道:
2016-07-12 11:27:57.846 INFO 4851 --- [ 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]
導致AtomikosJtaConfiguration
不匹配...
有人可以建議一個最佳實踐,以使Atomikos自動配置工作嗎?
因爲你正在添加你自己的'JtaTransactionManager'來禁用自動配置。 –
@ M.Deinum:謝謝。我已經評論了jta事務管理器,但不知何故本地事務管理器被春天啓動... – balteo
我想這是一個稍微不同的問題,但我怎麼才能找出這個'transactionManager' bean在自動配置中提到報告來自? – balteo