在web应用中通过以下方式装载spring bean context:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/conf/appContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>在tapestry4下引入tapestry-spring.jar,即可在页面中通过spring:访问spring的bean。
当时在servlet中如何访问这个spring context获得bean呢?使用global吗?
在网上找了资料也没有找到。只是自己试验出了一种方式,通过ServletContext访问,暂时先用着:
ServletContext sc = req.getSession().getServletContext();
WebApplicationContext wc = WebApplicationContextUtils
.getWebApplicationContext(sc);调用wc.getBean(beanID)就可以获得对应的bean了
本文介绍了一种在Servlet环境中通过ServletContext获取Spring Bean的方法,并提供了具体的实现步骤。
263

被折叠的 条评论
为什么被折叠?



