Web应用中加载Spring配置文件的三种方法

来源:互联网 发布:淘宝精细化运营 编辑:程序博客网 时间:2024/04/30 02:07
1、web.xml 
Xml代码 
  1. <web-app>  
  2. <context-param>  
  3. <param-name>contextConfigLocation</param-name>  
  4. <param-value>/WEB-INF/applicationContext-*.xml</param-value>  
  5. </context-param>  
  6. <listener>  
  7. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  8. </listener>  
  9. </web-app>  

2、web.xml
Xml代码 
  1. <web-app>  
  2. <context-param>  
  3. <param-name>contextConfigLocation</param-name>  
  4. <param-value>/WEB-INF/applicationContext-*.xml</param-value>  
  5. </context-param>  
  6. <servlet>  
  7. <servlet-name>SpringContextServlet</servlet-name>  
  8. <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>  
  9. <load-on-startup>1</load-on-startup>  
  10. </servlet>  
  11. </web-app>  

3、在(struts-config.xml)中加载 
Xml代码 
  1. <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">  
  2. <set-property property="contextConfigLocation"  
  3. value="/WEB-INF/applicationContext.xml,  
  4. /WEB-INF/action-servlet.xml"/>  
  5. </plug-in>   
原创粉丝点击