If @ConfigurationProperties binds the properties into an object, what is the usage of @ConfigurationProperties in building a DataSource?
application.properties
#Database
database1.datasource.url=jdbc:mysql://localhost/testdb
database1.datasource.username=root
database1.datasource.password=root
database1.datasource.driver-class-name=com.mysql.jdbc.Driver
Data Source Bean:
@Bean(name = "datasource1")
@ConfigurationProperties("database1.datasource")
@Primary
public DataSource dataSource(){
return DataSourceBuilder.create().build();
}
Also, if the data source properties is already bound using @ConfigurationProperties in a separate bean, do we still need to put the same annotation to the Data Source builder bean?
@Bean
@ConfigurationProperties("database1.datasource")
public DataSourceProps dataSourceProps(){
return new DataSourceProps();
}
@Bean(name = "datasource1")
// @ConfigurationProperties("database1.datasource") Is this necessary?
@Primary
public DataSource dataSource(){
return dataSourceProps().initializeDataSourceBuilder().type(HikariDataSource.class).build();
}