2015-12-11 12 views
1

В классе Сервет это можно получить пружине ApplicationContext таким образомКак получить весну ApplicationContext в ServletContextListener?

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

Как получить доступ к ApplicationContext в ServletContextListener, поскольку getServletContext() метод не доступен там?

ответ

1

В contextInitialized:

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