Reputation: 49
I've created a multiple datasource setup with spring-boot. It looks like this:
application.yaml:
app:
db1:
jdbc-url:...
username:...
password:...
db2:...
Config-class:
@Configuration(proxyBeanMethods = false)
public class DataSourceConfig {
@Bean(name = "db1")
@Primary
@ConfigurationProperties("app.db1")
public DataSource statusServiceDataSource(){
return DataSourceBuilder.create().build();
}
@Bean(name = "db2")
@ConfigurationProperties("app.db2")
public DataSource identifierResolverServiceDataSource(){
return DataSourceBuilder.create().build();
}
I use the datasource this way:
@Autowired
@Qualifier("db2")
DataSource db2;
Until here everything works fine. Now I wanted to include p6spy depending on a value of the properties, but I get different errors.
First approach:
return new P6DataSource(DataSourceBuilder.create().build());
leads to:
java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.
Second approach:
return DataSourceBuilder.create().type(P6DataSource.class).build();
leads to:
P6DataSource: no value for Real Data Source Name, cannot perform jndi lookup
Looking at the P6Spy docs, I thought my approach was enough, but It looks like it isn't. What can I do to solve the problem? Do I really have to go the whole way with defining jndi/lookUp names for my 7+ DataSources?
Also when looking up my datasource properties in application.yaml I get an error from IntelliJ saying "Cannot resolve configuration property", which is strange, as the app works just fine with all datasources without p6spy.
Upvotes: 0
Views: 424
Reputation: 1
I'm working in a similar solution. I couldn't use the spring boot autoconfiguration so... first thing to do is to add your maven dependency for p6spy. Then, you need a psy.properties
where you could add your driver to driverlist like this (DB2 example)
driverlist=com.ibm.db2.jcc.DB2Driver
I had troubles at first using P6DataSource, so I tried the url + driver approach in order to test the library configurations.
Once the url + driver approach worked for me, I returned to P6DataSource
https://p6spy.readthedocs.io/en/latest/integration.html
Maybe you could try it
Upvotes: 0