micronaut-projects / micronaut-projects/micronaut-data
Multiple datasources configuration not working
- Dominant language
- Java
- Stars
- 482
- Forks
- 229
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 32
Description
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:
```java
@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](https://github.com/micronaut-projects/micronaut-core/files/14991595/Stack.trace.txt)
This is the related discussion on Slack channel #gcn-micronaut-help:
[Conversation Link](https://proddev-paas-fmw.slack.com/archives/C018V58P05C/p1711974070480689)
Contributor guide
Assessment
This issue has not been assessed yet.