Spring可以轻松集成到任何基于Java的Web框架中。你需要做的就是在
web.xml中声明
ContextLoaderListener并使用
contextConfigLocation设置要加载的上下文文件。
<context-param>:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value></context-param><listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class></listener>
然后,你可以使用WebApplicationContext来获取bean的句柄。
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servlet.getServletContext());SomeBean someBean = (SomeBean) ctx.getBean("someBean");


