spring-batch-lightmin icon indicating copy to clipboard operation
spring-batch-lightmin copied to clipboard

Can't stop a job due to multiple transaction managers

Open sallampalli opened this issue 5 years ago • 2 comments

Scenario

  1. Embedded Lightmin approach
  2. Multiple Datasources configured due to functional needs
  3. The primary datasource is configured and fed to Spring batch using DefaultBatchConfigurer @Bean BatchConfigurer customBatchConfig() { DefaultBatchConfigurer customBatchConfig = new DefaultBatchConfigurer(primaryDataSource()); return customBatchConfig; } This will configure the default transactionManager
  4. The second datasource is configured with JPA so another customTransactionManager is configured to manage the JPA entities

Versions

  • Lightmin 2.1.1
  • Spring Boot 2.2.6.RELEASE

Problem Statement

  1. When I tried stopping a job, got an exception "Could not stop a job" .
  2. I had to run in DEBUG mode to figure out underlying exception, turns out that it is because of multiple transaction managers. org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.transaction.TransactionManager' available: expected single matching bean but found 4: transactionManager,customTransactionManager,lightminTransactionManager,lightminServerSchedulerTransactionManager
  3. When a job is stopped, lightmin uses the jobOperator to make an update in the database and it uses @Transacational on that method . Looks like it is not able to figure out which transaction manager to use since it found 4 of them

Question Is there a way we can tell Lightmin to use the default spring batch config implementation (DefaultBatchConfigurer) instead of its own ? I saw a similar issue couple of years back : https://github.com/tuxdevelop/spring-batch-lightmin/issues/19

sallampalli avatar Jul 10 '20 04:07 sallampalli

Hello team - can you please look into it or provide some work around as it is impacting us as well.

toneeraj avatar Jul 22 '20 17:07 toneeraj

Hello sallampalli, I just tried to load the DefaultBatchConfigurer and I had no problems with it. The Lightmin Bean is provided with a @ConditionalOnMissingBean(BatchConfigurer.class) annotation. Make sure you create the beans in the correct order. From the current point of view I cannot guarantee that the full functionality of the Lightmin platform will be maintained. Starting jobs still seems to be possible. If you have any trouble setting this up you can provide us an minimal dummy project, so we can better understand your situation. Best regards, Andreas

adaptivecodes avatar Sep 10 '20 14:09 adaptivecodes