Description
Description
If multiple PlatformTransactionManager
s are configured, Mongock
s bootstrapping logic fails with the error "Multiple PlatformTransactionManager candidates are found" (this is a typical Spring dependency injection failure!)
PRIORITY
NORMAL
Version and environment
Mongock
- Mongock version: 5.4.0 (I think every version suffers from this error since the introduction of
SpringDataMongoV4Context
) - Modules involved: SpringBoot v3.4.3, MongoDB 7.0
- How Mongock is used: annotation approach
Environment
- SpringBoot, Spring Data MongoDB and Spring Data JDBC
- Infrastructure: Kubernetes
Steps to Reproduce
- Define multiple beans of
PlatformTransactionManager
, e.g.:
@Bean
MongoTransactionManager mongoTransactionManager() {
...
}
@Bean
DataSourceTransactionManager jdbcTransactionManager() {
...
}
@Bean
RabbitTransactionManager rabbitTransactionManager() {
...
}
Behaviour
Expected behavior:
Depends on the prefered solution/conception how to handle multiple PlatformTransactionManagers
.
My minimum wish: silent/graceful skip when multiple PlatformTransactionManagers
are found (which in turns disables the transactional support of Mongock)
Actual behavior:
Spring fails to wire the SpringDataMongoV4Context
or more concrete SpringDataMongoV4ContextBase#connectionDriver
due to its method signature:
@Bean
public ConnectionDriver connectionDriver(MongoTemplate mongoTemplate, CONFIG config, MongoDBConfiguration mongoDbConfig, Optional<PlatformTransactionManager> txManagerOpt) {
DRIVER driver = this.buildDriver(mongoTemplate, config, mongoDbConfig);
this.setGenericDriverConfig(config, txManagerOpt, driver);
this.setMongoDBConfig(mongoDbConfig, driver);
driver.initialize();
return driver;
}
Injection of Optional<PlatformTransactionManager>
fails, as multiple beans of that type exist!
How often the bug happens:
100%
Additional context
There is a similar issue but it is already closed/solved: #676