I followed the documentation and created some sourcecode that is quite identical to the given example. When I run my code I get this exception:
java.lang.RuntimeException: Driver org.mariadb.jdbc.Driver claims to not accept jdbcUrl, jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
The strange thing is that two things are mixed:
- the h2-jdbcUrl is treated by the mariaDB-driver
- the query that my previously existing code runs it targetted against mariaDB (I have not yet written any code that used the second datasource)
These are my beans:
@Bean
@Primary
@ConfigurationProperties("datasources.first")
public DataSourceProperties firstDataSourceProperties() {
return new DataSourceProperties();
}
@Bean
@Primary
@ConfigurationProperties("datasources.first.configuration")
public HikariDataSource firstDataSource() {
return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
}
@Bean
@ConfigurationProperties("datasources.second")
public DataSourceProperties secondDataSourceProperties() {
return new DataSourceProperties();
}
@Bean
@ConfigurationProperties("datasources.second.configuration")
public HikariDataSource secondDataSource() {
return secondDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
}
My application.yml looks like this:
datasources:
first:
jdbcUrl: jdbc:mariadb://...
username: ...
password: ...
driver-class-name: org.mariadb.jdbc.Driver
second:
jdbcUrl: jdbc:h2:/tmp/test;DB_CLOSE_ON_EXIT=FALSE
username: ...
password: ...
driver-class-name: org.h2.Driver
This is the code that causes the exception:
@Component
public class Updater {
@Autowired
JdbcTemplate jdbcTemplate;
@Autowired
Queries queries;
public List<User> getActiveUsers() throws Exception {
List<User> users = jdbcTemplate.query(queries.getActive(), new UserRowMapper());
return users;
}
In order to diagnose this further I enabled the configprops and beans endpoints and checked their output.
The config looks good and the beans too:
Config (one of many):
"firstDataSourceProperties": {
"prefix": "datasources.first",
"properties": {
"password": "******",
"initializationMode": "EMBEDDED",
"driverClassName": "org.mariadb.jdbc.Driver",
"generateUniqueName": false,
"xa": {
"properties": {}
},
"separator": ";",
"platform": "all",
"continueOnError": false,
"username": "..."
}
Bean (one of many):
"firstDataSource": {
"aliases": [],
"scope": "singleton",
"type": "com.zaxxer.hikari.HikariDataSource",
"resource": "...Application",
"dependencies": [
"firstDataSourceProperties"
]
}
I use Spring Boot 2.2.6
Driver org.mariadb.jdbc.Driver claims to not accept jdbcUrl, jdbc:h2:...although your comment solved my (future ?) problem with differentiating two JdbcTemplates - Margedorg.h2.jdbc.JdbcSQLSyntaxErrorException, that means the second datasource uses the correct driver - Marged