public class SpringContextUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public final void setApplicationContext(ApplicationContext arg0)
throws BeansException {
SpringContextUtil.applicationContext = arg0;
}
public final static ApplicationContext getApplicationContext() {
return applicationContext;
}
public final static Object getBean(Class clazz) throws BeansException {
return applicationContext.getBean(clazz);
}
public final static Object getBean(String name) throws BeansException {
return applicationContext.getBean(name);
}
}
spring-mvc.xml配置
<bean id="springContextUtil" class="com.enci.isms.common.utils.SpringContextUtil"></bean>