在服务类中,可以这样获得spring ApplicationContext

ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());


由于无法访问ApplicationContext方法,如何访问ServletContextListener中的getServletContext()

最佳答案

contextInitialized中:

public void contextInitialized(final ServletContextEvent event)
{
    ApplicationContext appCtx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
}

09-27 17:22