简体   繁体   English

当我添加 Spring 批处理配置时,出现错误

[英]When I add Spring batch configuration I get error

In my project I use multiple schema (multiple dataSource)在我的项目中,我使用多个模式(多个数据源)

When I add Spring batch configuration I get error: No qualifying bean of type 'org.springframework.transaction.PlatformTransactionManager' available: expected single matching bean but found 5当我添加 Spring 批处理配置时,我收到错误: No qualifying bean of type 'org.springframework.transaction.PlatformTransactionManager' available: expected single matching bean but found 5

but when I remove spring batch configuration the error is removed.但是当我删除 spring 批处理配置时,错误被删除。

@Configuration
@EnableBatchProcessing
@Import(MyDataSourceClassConfig.class)
public class TestBatchJobConfiguration extends DefaultBatchConfigurer {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;
    @Autowired
    private StepBuilderFactory stepBuilderFactory;
   ....


}

if you also facing same problem, you need to verify two point.如果您也面临同样的问题,则需要验证两点。

First you have to do not create a bean transaction named transactionManager (this default one used by spring batch)首先,您必须不要创建名为 transactionManager 的 bean 事务(这是 spring 批处理使用的默认事务)

Second you need to override getTransactionManager to specify which transactionManager you want to use and which dataSource you want to use其次,您需要覆盖 getTransactionManager 以指定要使用的事务管理器和要使用的数据源

@Autowired
@Qualifier("myPersonalTransactionManager")
private PlatformTransactionManager transactionManager;


@Override
public PlatformTransactionManager getTransactionManager() {
    return transactionManager;
}
@Override
@Autowired
public void setDataSource(@Qualifier("thirdDataSource") DataSource batchDataSource) {
    super.setDataSource(batchDataSource);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在web.xml中添加spring安全配置时,我收到错误“找不到WebApplicationContext:没有注册ContextLoaderListener?” - When ever i add spring security configuration in web.xml i get the error “No WebApplicationContext found: no ContextLoaderListener registered?” 处理器中的Spring Batch配置错误 - Spring Batch configuration error in processor Spring Batch:如何在XML配置中指定步骤的类? - Spring Batch: How can I specify a class of a step in XML configuration? 如何将动态属性分配给 Spring Batch 配置? - How could I assign dynamic properties to a Spring Batch configuration? 我可以将 Spring 批量配置更改为静态运行吗? - Can I change Spring Batch configuration to run statically? 当我在 Spring 中添加 CorsMapping 配置时,为什么 Jackson 会破坏我的 LocalDateTime? - Why does Jackson destructure my LocalDateTime when I add a CorsMapping configuration in Spring? 我在使用 spring boot 版本 2.2.0 的 spring 批处理中遇到错误 - I am getting error in spring batch with spring boot version 2.2.0 添加到请求 DTO 时收到 415 错误消息 - I get an 415 error message when I add to request DTO 配置Spring-BOOT当我运行时我解决异常 - Configuration Spring-BOOT when i run i resolve exception 尝试对Spring Kafka Consumer进行单元测试时,如何解决配置错误? - How do I resolve an error in my configuration when trying to unit test a Spring Kafka Consumer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM