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.