I have something like this.
@Qualifier("dataSource")
@Profile("test")
@Bean(name = {"dataSource", "batchDataSource", "readDataSource"})
public DataSource testDataSource() {
return buildDatasource(driverClass, url, writeUsername, writePassword);
}
@Bean
@Qualifier("dataSource")
@Profile({"prod"})
public DataSource dataSource() {
return buildDatasource(driverClass, url, writeUsername, writePassword);
}
@Bean(name = {"batchDataSource", "readDataSource"})
@Profile({"prod"})
public DataSource createReadDataSource() {
return buildDatasource(driverClass, batchUrl, readUsername, readPassword);
}
@Bean(name = {"dataSource", "batchDataSource", "readDataSource"})
public DataSource testDataSourceForNonProfile() {
return null;/*JUST DEBUGGING*/
}
/*-----------------------------------------------DATASOURCES END--------------------------------------------------*/
@Profile("prod")
@Bean(name = {"readSessionFactory", "batchSessionFactory"})
public SessionFactory createReadSessionFactory(@Qualifier("batchDataSource") DataSource dataSource) {
return getSessionFactory(dataSource);
}
i have set
-Dspring.profiles.active=prod
But when the readSessionFactory is call the datasource received is this
public DataSource dataSource()
Instead of
public DataSource createReadDataSource()
Even when the (@Qualifier("batchDataSource") is set i dont understand why and driving me nuts.
If i delete/comment the bean declaration the one with non profile set. It works Spring calls the batchDataSource
//METHOD COMMENT/DELETED
@Bean(name = {"dataSource", "batchDataSource", "readDataSource"})
public DataSource testDataSourceForNonProfile() {
return null;
}
Sorry if the question is plain.