Answer the question
In order to leave comments, you need to log in
How to properly declare complex beans?
Hello dear developers!
I use spring recently, so I have a question.
There is a project written in spring, configuration via Java was used.
Configuration class:
@SpringBootApplication
@ComponentScan
public class Application extends SpringBootServletInitializer {
// ...
@Bean
@Primary
@ConfigurationProperties(prefix = "datasource.one")
DataSource one() {
return DataSourceBuilder.create().build();
}
@Bean
@ConfigurationProperties(prefix = "datasource.two")
DataSource two() {
return DataSourceBuilder.create().build();
}
@Bean
DAO dao(DAOImpl dao) {
return dao;
}
// ...
}
@Component
public class DAOImpl implements DAO {
@Autowired
@Qualifier("one")
private DataSource grad;
@Autowired
@Qualifier("two")
private DataSource phone;
//... сложная бизнес-логика для работы с бд
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question