繁体   English   中英

如何在ServletContextListener中获取Spring ApplicationContext?

[英]How to get spring ApplicationContext in ServletContextListener?

在服务类中,可以通过这种方式获取spring ApplicationContext

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

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

contextInitialized

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM