首页 > 技术文章 > 将ApplicationContext注入到一个Bean有哪些方法

hzzhero 2017-09-06 23:46 原文

1    直接@Autowire,按类型注入


    @utowired
    private ApplicationContext context;

 

2  要注入的类实现ApplicationContextAware,只要实现了ApplicationContextAware,创建的bean中就已经注入了ApplicationContext

3 Spring4的新特性---如果一个类的构造方法中有类参数,spring 会尝试从容器中找到对应的bean作为参数的值

 

推荐阅读