1.在web.xml配置启动的listener
<listener>
<listener-class>com.my.core.web.listener.SpringLoaderListener</listener-class>
</listener>
启动容器的代码
public class SpringLoaderListener extends ContextLoaderListener
{
public void contextInitialized(ServletContextEvent event)
{
super.contextInitialized(event);
ServletContext context = event.getServletContext();
//设置容器为Servlet容器
ContextUtil.setServletContext(context);
/*WebApplicationContextUtils是org.springframework.web.context.support.
WebApplicationContextUtils中的类*/
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
ContextUtil.setContext(ctx);
}
}