在web應用中通過以下方式裝載spring bean context:
<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訪問,暫時先用着:
WebApplicationContext wc = WebApplicationContextUtils
.getWebApplicationContext(sc);
調用wc.getBean(beanID)就可以獲得對應的bean了