在Spring Boot/Spring Batch应用程序上配置Atomikos的问题 [英] Issue with configuring Atomikos on a Spring Boot / Spring Batch application

查看:221
本文介绍了在Spring Boot/Spring Batch应用程序上配置Atomikos的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让Atomikos与我的Spring Boot/Spring Batch应用程序一起使用.

I am trying to get Atomikos to work with my Spring Boot/Spring Batch application.

这是我代码的相关部分:

Here is are the relevant portions of my code:

数据源配置:

@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自动配置依赖项:

Atomikos auto-config dependency:

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 ...谁能帮忙吗?

I am not sure why Atomikos is not auto-configured... Can anyone please help?

编辑:我已经注释掉了JTA transactionManager bean,现在我得到以下自动配置报告:

edit: I have commented out the JTA transactionManager bean and I now get the following auto-configuration report:

   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交易管理器被选中?

How can I make sure the Atomikos transaction manager is picked up?

编辑2 :我排除了以下TransactionManager类:

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

但我似乎SimpleBatchConfigurationSimpleTaskConfiguration仍然对我强加了几个TransactionManager类之一:

but I seems that SimpleBatchConfiguration and SimpleTaskConfiguration still force one of several TransactionManager class(es) on me:

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自动配置正常工作吗?

Can someone please advise a best practice in order to get Atomikos auto-configuration to work?

推荐答案

您无需添加Atomikos或Bitronix即可为数据源指定PlatformTransactionManager.请参阅实体不持久.是RepositoryItemWriter& SimpleJpaWriter线程安全吗?.

You don't need to add Atomikos or Bitronix to specify a PlatformTransactionManager for your datasource. See Entities not persisting. Are RepositoryItemWriter & SimpleJpaWriter thread-safe?.

这篇关于在Spring Boot/Spring Batch应用程序上配置Atomikos的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆