3

Ich versuche Atomikos mit meiner Spring Boot/Spring Batch-Anwendung zu arbeiten.Problem mit der Konfiguration von Atomikos in einer Spring Boot/Spring Batch-Anwendung

Hier sind sind die jeweiligen Teile meines Codes:

Datenquelle config:

@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 Auto-Config-Abhängigkeit:

compile("org.springframework.boot:spring-boot-starter-jta-atomikos") 

Mein application.properties:

spring.datasource.application.driver-class-name=org.postgresql.xa.PGXADataSource 
spring.datasource.batch.driver-class-name=org.postgresql.xa.PGXADataSource 

Hier ist die automatische Konfigurationsbericht ist:

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) 

Ich bin nicht sicher, warum Atomikos nicht automatisch konfiguriert ist ... Kann mir jemand bitte helfen?

bearbeitet: Ich habe die JTA transaction Bohne kommentiert und ich jetzt den folgenden Auto-Konfigurationsbericht:

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) 

Wie kann ich sicherstellen, dass die Atomikos Transaktionsmanager abgeholt werden?

bearbeiten 2: Ich habe TransactionManager Klassen ausgeschlossen wie folgt:

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

aber ich scheint, dass SimpleBatchConfiguration und SimpleTaskConfiguration immer noch eine der TransactionManager Klasse mehrere zwingen (n) auf mich:

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] 

verursacht die AtomikosJtaConfiguration nicht übereinstimmen ...

Kann jemand bitte eine Best Practice empfehlen, um Atomikos Autokonfiguration zu erhalten?

+1

Da Sie Ihren eigenen 'JtaTransactionManager' hinzufügen, der die automatische Konfiguration deaktiviert. –

+0

@ M.Deinum: danke. Ich habe den jta transaction manager auskommentiert, aber irgendwie wird ein lokaler transaction manager vom Spring Boot ... – balteo

+0

Ich denke, es ist eine etwas andere Frage, aber wie kann ich herausfinden, wo diese 'transactionManager'-Bean in der Autokonfiguration erwähnt wird Bericht kommt von? – balteo

Antwort

-1

Sie müssen Atomikos oder Bitronix nicht hinzufügen, um einen PlatformTransactionManager für Ihre Datenquelle anzugeben. Siehe Entities not persisting. Are RepositoryItemWriter & SimpleJpaWriter thread-safe?.

+0

Hallo delewis. Gemäß diesem Beitrag: http: // stackoverflow.com/questions/26820818, scheint es die einzige Möglichkeit zu sein, die Job-Repository-Daten und die Anwendungsdaten in zwei verschiedenen Datenbanken zu haben, um XA/verteilte Transaktionen zu verwenden. – balteo

+0

Ich bin mir daher nicht sicher, ob das andauernde Problem mit der Thread-Sicherheit zusammenhängt. – balteo

+0

Meine Anwendung verfügt außerdem über zwei Datenquellen, die als Teil eines Stapeljobs miteinander lesen und schreiben. Obwohl sich der Beitrag auf Thread-Sicherheit bezieht, ist das Problem, das ich mit nicht persistenten Entitäten hatte, ähnlich wie bei Ihnen, und das Hinzufügen eines PlatformTransactionManagers zu meiner Datenquelle und Step-Beans hat das Problem behoben. – delewis