启动时初始化Spring上下文环境工具类
This commit is contained in:
parent
59963010be
commit
f332818593
common/src/main
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -11,4 +11,7 @@
|
||||||
<!-- 装载service -->
|
<!-- 装载service -->
|
||||||
<context:component-scan base-package="**.service" />
|
<context:component-scan base-package="**.service" />
|
||||||
|
|
||||||
|
<!-- 启动时初始化Spring上下文环境工具类 -->
|
||||||
|
<bean id="springContextUtil" class="com.zheng.common.util.SpringContextUtil"></bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
Loading…
Reference in New Issue