After Spring Boot 2.0 Migration: Jdbcurl Is Required With Driverclassname

After Spring Boot 2.0 migration: jdbcUrl is required with driverClassName

In case you do need to define dataSource(), for example when you have multiple data sources, you can use:

@Autowired Environment env;

@Primary
@Bean
public DataSource customDataSource() {

DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("custom.datasource.driver-class-name"));
dataSource.setUrl(env.getProperty("custom.datasource.url"));
dataSource.setUsername(env.getProperty("custom.datasource.username"));
dataSource.setPassword(env.getProperty("custom.datasource.password"));

return dataSource;

}

By setting up the dataSource yourself (instead of using DataSourceBuilder), it fixed my problem which you also had.

The always knowledgeable Baeldung has a tutorial which explains in depth.

How to configure mutiple DataSource with driver-class in Spring?

Looks like you just need to add the @Bean annotation to dataSourceTest().

@Bean
@ConfigurationProperties(prefix = "spring.datasource.testdb")
@Primary

Also, for the Hikari connection pool (which is the default connection pool), the url property is jdbc-url, not url. So change

spring.datasource.testdb.url=jdbc:mariadb://localhost/mytable

to

spring.datasource.testdb.jdbc-url=jdbc:mariadb://localhost/mytable

For more info, and other possible solutions see: After Spring Boot 2.0 migration: jdbcUrl is required with driverClassName

Hope this helps.



Related Topics



Leave a reply



Submit