3

私はSpring Boot/Spring BatchアプリケーションでAtomikosを動作させようとしています。Springブート/ 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 
ここ

は、IS私のコードの関連部分ですここでは0

が自動設定レポートです:

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 Beanをコメントアウトしていると私は今、次の自動設定のレポートを取得する:

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

@EnableAutoConfiguration(exclude = {DataSourceTransactionManagerAutoConfiguration.class, TransactionAutoConfiguration.class}) 

を私はSimpleBatchConfigurationSimpleTaskConfigurationはまだ私にTransactionManagerいくつかのクラス(ES)のいずれかを強制するようだ:次のように私はTransactionManagerクラスを除外した

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の自動設定を有効にするためにベストプラクティスをアドバイスできますか?

+1

自動設定を無効にする独自の 'JtaTransactionManager'を追加しているためです。 –

+0

@ M.Deinum:ありがとう。私はjtaトランザクションマネージャーをコメントアウトしていますが、どういうわけかローカルトランザクションマネージャーは春のブートによってピックアップされています... – balteo

+0

私はそれが少し異なる質問だと思いますが、どのように私はこの 'transactionManager' beanがauto-configuration報告は? – balteo

答えて

-1

データソースのPlatformTransactionManagerを指定するためにAtomikosまたはBitronixを追加する必要はありません。 Entities not persisting. Are RepositoryItemWriter & SimpleJpaWriter thread-safe?を参照してください。

+0

こんにちは。この投稿によると:http:// stackoverflow。com/questions/26820818では、2つの異なるデータベースにジョブリポジトリデータとアプリケーションデータを格納する唯一の方法は、XA /分散トランザクションを使用することです。 – balteo

+0

したがって、永続的な問題がスレッドの安全性に関係しているかどうかはわかりません。 – balteo

+0

私のアプリケーションには、バッチジョブの一部として相互に読み書きする2つのデータソースもあります。ポストがスレッドの安全性を参照しているにもかかわらず、保持していないエンティティの問題はあなたのものと似ていて、データソースとステップBeanにPlatformTransactionManagerを追加することで問題が解決しました。 – delewis

関連する問題