Posted on 2008-12-16 22:40
sailor 閱讀(821)
評論(0) 編輯 收藏 所屬分類:
spring
1、使用 web.xml 來使 Web 容器加載 Spring
web.xml :
通過:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener-->
或:
<servlet>
<servlet-name>SpringContextServlet</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Web 容器會自動加載 /WEB-INF/applicationContext.xml 初始化 ApplicationContex t實例;
也可以通過
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-*.xml</param-value>
</context-param>
使 Web 容器加載指定名稱路徑的 Spring 配置文件。
2、通過 struts-config.xml 來使 Web 容器加載 Spring
struts-config.xml
通過
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml,
/WEB-INF/action-servlet.xml"/>
</plug-in>
來加載 Spring 配置文件。
文章出處:http://www.diybl.com/course/3_program/java/javashl/200855/112963.html