Need to configure my JPA layer to use a TransactionManager (Spring Cloud Task + Batch register a PlatformTransactionManager unexpectedly)

前端 未结 1 1638
醉梦人生
醉梦人生 2021-01-07 14:27

I am using Spring Cloud Task + Batch in a project. I plan to use different datasources for business data and Spring audit data on the task. So I configured som

1条回答
  •  不思量自难忘°
    2021-01-07 14:38

    The problem comes when SimpleBatchConfiguration+DefaultBatchConfigurer expose a PlatformTransactionManager bean,

    As you mentioned, this is indeed what was reported in BATCH-2788. The solution we are exploring is to expose the transaction manager bean only if Spring Batch creates it.

    In the meantime you can set the property spring.main.allow-bean-definition-overriding=true to allow bean definition overriding and set the transaction manager you want Spring Batch to use with BatchConfigurer#getTransactionManager. In your case, it would be something like:

    @Bean
    public BatchConfigurer batchConfigurer() {
        return new DefaultBatchConfigurer(this.singletonNotExposedSpringDatasource()) {
            @Override
            public PlatformTransactionManager getTransactionManager() {
                return new MyTransactionManager();
            }
        };
    }
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题