micronaut-data
micronaut-data copied to clipboard
Multiple datasources configuration not working
We are trying to create 2 datasource beans in our Micronaut appilcation. The beans are getting created successfully as we are able to obtain them from application context. Here is how we created Datasource beans:
@Bean
@Singleton
@Named("appshellDatasource")
public DataSource appshellDatasource(){
return new HikariDataSource(getHikariConfig(podConfigUtil.getAppshellSchemaUser(), podConfigUtil.getAppshellPwd()));
}
@Bean
@Singleton
@Named("common")
public DataSource commonDataSource() {
return new HikariDataSource(getHikariConfig(podConfigUtil.getCommonSchemaUser(), podConfigUtil.getCommonPwd()));
}
But, when we are trying to query the database with any of the datasources we are getting the below exception:
24-04-01 17:49:35,271 ERROR [default-nioEventLoopGroup-1-3] i.m.h.s.RouteExecutor: - msg: Unexpected error occurred: Error instantiating bean of type [io.micronaut.data.connection.jdbc.advice.ContextualConnection$Intercepted]Message: Multiple possible bean candidates found: [DefaultDataSourceConnectionOperations, DefaultDataSourceConnectionOperations]
Please find the detailed stack trace attached:
Stack trace.txt
This is the related discussion on Slack channel #gcn-micronaut-help: Conversation Link
@radovanradic please look into this
I did investigate it before, and the problem is that:
@Prototype
public final class ContextualConnectionInterceptor implements MethodInterceptor<Connection, Object> {
private final ConnectionOperations<Connection> connectionOperations;
/**
* Default constructor.
*
* @param beanContext The bean context
* @param qualifier The qualifier
*/
@Internal
ContextualConnectionInterceptor(BeanContext beanContext, Qualifier<ConnectionOperations> qualifier) {
connectionOperations = beanContext.getBean(Argument.of(ConnectionOperations.class, Connection.class), qualifier);
}
Being injected without the qualifier.
@dstepanov have you tried annotating @Parameter on the qualifier? Otherwise seems like a regression in core
No, but I saw in debugger that the qualifier is replaced with null in the bean context.
We run into the same problem. If multiple datasources are defined but none is called 'default' any bean with an around advice (@Validated, @Transactional) causes the whole thing to break as we get multiple candidate beans.
When we defined a default datasource it fixes itself but I'm not sure about the implications.
Is it known when this regression was introduced? We'd like to roll back to the version before that as we've just upgraded all our code to MN4 (yes, we're late)