package com.epdc.common; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.web.context.ContextLoader; import org.springframework.web.context.WebApplicationContext; /** * @author lsh * */ public class SpringContextUtil { private static String configName = "classpath:applicationContext*.xml"; private static ApplicationContext context; public static Object getWebBean(String name) { WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); return wac.getBean(name); } public static Object getMainBean(String name) { if (context == null) { context = new ClassPathXmlApplicationContext(configName); } return context.getBean(name); } public static void main(String args[]) throws Exception { } }