如何在ServletContextListener中获取springApplicationContext?
How to get spring ApplicationContext in ServletContextListener?
在 servet class 中可以这样得到 spring ApplicationContext
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
如何在 ServletContextListener
中访问 ApplicationContext
,因为那里无法访问 getServletContext()
方法?
在contextInitialized
中:
public void contextInitialized(final ServletContextEvent event)
{
ApplicationContext appCtx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
}
在 servet class 中可以这样得到 spring ApplicationContext
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
如何在 ServletContextListener
中访问 ApplicationContext
,因为那里无法访问 getServletContext()
方法?
在contextInitialized
中:
public void contextInitialized(final ServletContextEvent event)
{
ApplicationContext appCtx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
}