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
Password Validate 8 Digits, Contains Upper, Lowercase, and a Special Character
Spring Data JPA Problem With Updating Multiple Entities
Post and Get for the Same Url - Controller - Spring
Setting Default Values to Null Fields When Mapping With Jackson
How to Avoid Thread.Sleep in Unit Tests
How to Set a Ttl for @Cacheable
Scheduling a Job With Spring Programmatically (With Fixedrate Set Dynamically)
Typecasting an Object from Parent Class to Child
Spring Boot Application Shutdown Immediate After Starting
How to Change Cookie Processor to Legacycookieprocessor in Tomcat 8
Spring Webclient: How to Stream Large Byte[] to File
Deserialization With @Jsonsubtypes for No Value - Missing Property Error
How to Do Name Validation Allowing Alphabet, Spaces and Dot in Android
Automatically Convert Style Sheets to Inline Style
Splitting a String Containing Special Characters in to Individual Characters