您的位置:首页 > 编程语言 > Java开发

获得spring容器上下文

2015-07-14 21:24 393 查看
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringContextUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;     //Spring应用上下文环境

/**
* 实现ApplicationContextAware接口的回调方法,设置上下文环境
* @param applicationContext
* @throws BeansException
*/
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringContextUtil.applicationContext = applicationContext;
}

/**
* @return ApplicationContext
*/
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
}


在applicationcontext.xml

<!-- 辅助类型 -->

<bean id="springContextUtil" class="com.biz.util.SpringContextUtil" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: