启动时初始化Spring上下文环境工具类

This commit is contained in:
shuzheng 2016-10-18 17:52:25 +08:00
parent 59963010be
commit f332818593
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package com.zheng.common.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* 资源文件读取工具
*
* @author shuzheng
* @date 2016年10月15日
*/
public class SpringContextUtil implements ApplicationContextAware {
public static SpringContextUtil springContextUtil = new SpringContextUtil();
private static ApplicationContext context = null;
public final static synchronized SpringContextUtil getInstance() {
return springContextUtil;
}
private SpringContextUtil() {
super();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context = applicationContext;
}
public static Object getBean(String name) {
return context.getBean(name);
}
}

View File

@ -11,4 +11,7 @@
<!-- 装载service -->
<context:component-scan base-package="**.service" />
<!-- 启动时初始化Spring上下文环境工具类 -->
<bean id="springContextUtil" class="com.zheng.common.util.SpringContextUtil"></bean>
</beans>