Can't stop a job due to multiple transaction managers
Scenario
- Embedded Lightmin approach
- Multiple Datasources configured due to functional needs
- 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 - 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
- When I tried stopping a job, got an exception "Could not stop a job" .
- 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 - 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
Hello team - can you please look into it or provide some work around as it is impacting us as well.
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