将ApplicationContext注入到一个Bean有哪些方法

1    直接@Autowire,按类型注入


    @utowired
    private ApplicationContext context;

 

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

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

 

posted on 2017-09-06 23:46  编世界  阅读(1941)  评论(0编辑  收藏  举报