You can also use @Autowired for interfaces that are well-known resolvable dependencies: BeanFactory , ApplicationContext , Environment , ResourceLoader , ApplicationEventPublisher , and MessageSource . These interfaces and their extended interfaces,such as ConfigurableApplicationContext or ResourcePatternResolver , are automatically resolved, with no special setup necessary
1 2 3 4 5 6 7
publicclass{
private ApplicationContext context; public(){ }
}
@Primary
1 2 3 4 5 6 7 8 9
@Configuration publicclassMovieConfiguration{ @Bean @Primary//如果只需要注入一个bean,这个优先注入 public MovieCatalog firstMovieCatalog(){ ... } @Bean public MovieCatalog secondMovieCatalog(){ ... }
近期评论