`
bazhuang
  • 浏览: 147449 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

bean中拿到ApplicationContext对象

    博客分类:
  • java
阅读更多
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if (bean instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
		}
		if (bean instanceof ApplicationEventPublisherAware) {
			((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
		}
		if (bean instanceof MessageSourceAware) {
			((MessageSourceAware) bean).setMessageSource(this.applicationContext);
		}
		if (bean instanceof ApplicationContextAware) {
			((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
		}
		return bean;
	}


这个方法是定义在ApplicationContextAwareProcessor中的,一般都会注入到BeanFactory中。
从上面可以看出想要拿到ApplicationContext的方法就比较多了,看需要吧。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics