Spring boot 梳理 - SpringBoot中注入ApplicationContext物件的三種方式
阿新 • • 發佈:2018-12-27
- 直接注入(Autowired)
-
@Configuration public class OAConfig { @Autowired private ApplicationContext applicationContext; @Bean public PersonUtils personUtil(){ boolean bool=applicationContext.containsBean("aa"); System.out.println("containsBean:aa:
-
- 構造器方法注入
-
@Component public class User{ private ApplicationContext applicationContext; public User(ApplicationContext applicationContext) {
-
- 手動構建類實現介面
-
/** * Spring的ApplicationContext的持有者,可以用靜態方法的方式獲取spring容器中的bean * * @author yj * @date 2018年5月27日 下午6:32:11 */ @Component public class SpringContextHolder implements ApplicationContextAware {
-