当前位置: 首页 > 知识库问答 >
问题:

在Spring Boot/Spring批处理应用程序上配置Atomikos的问题

漆雕奇逸
2023-03-14

我试图让原子与我的Spring Boot/Spring Batch应用程序一起工作。

以下是我代码的相关部分:

数据源配置:

@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 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:我排除了TransactionManager类,如下所示:

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

但是我似乎SimpleBatchConfigurationSimpleTaskConfiguration仍然将几个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不匹配。。。

有人能建议一个最佳实践,以使原子自动配置工作?

共有1个答案

高寒
2023-03-14

您不需要添加原子或Bitronix即可为您的数据源指定PlatformTransactionManager。请参阅实体未持久化。是RepositoryItemWriter

 类似资料:
  • 我在一个Spring Boot应用程序中定义了多个Spring批处理作业。例如,job1、Job2。等等。 null

  • 我正在设置Spring Cloud Data Flow的实例。我运行了以下命令: 在第二步中,我使用的是postgres数据库,而不是默认的h2。 我已经开发了一个Spring Boot作业,使用spring批处理部署在这个平台窗体中。该作业使用两个数据源:Spring的springclouddataflow和任务元数据,以及我的业务逻辑的billrun。当我在本地运行应用程序时,它会像预期的那样

  • 我是新的Spring批与引导。我在使用postgres配置jobRepositoryFactory bean作为数据库时遇到了一个问题。下面是我的配置类。 下面是Spring boot App run的输出 我已经在我的configuration类中配置了bean。我错过了什么?

  • 我们正在处理一个Spring批处理项目(Spring Boot1.2.2.Release),要求使用Spring SFTP集成以一定频率轮询从服务器位置读取文件。我们使用java config实现了Spring批处理,并在使用Spring Integration java config的过程中实现了Spring批处理。我找不到描述上述情况的例子。我浏览了各种链接,但看到的主要是XML配置示例。 h

  • 我有下一个spring批处理配置类: 启动应用程序时,我收到下一个异常:

  • 我需要依次执行七个不同的流程(一个接一个)。数据存储在Mysql中。我正在考虑以下选项,如果我错了,或者有更好的解决方案,请纠正我。 要求: > 需要分块处理数据。 我的解决方案和问题:数据读取: 使用JdbcCursorItemReader读取数据,因为这是性能最好的db阅读器-但是,SQL非常复杂,所以我可能不得不考虑使用JdbcTemboard的自定义ItemReader?这让我在处理数据时