首页 > 编程语言 > 详细

S(Spring)S(Struts2)框架整合之配置web.xml文件

时间:2017-04-25 18:03:13      阅读:170      评论:0      收藏:0      [点我收藏+]
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Struts Blank</display-name>
   <!-- 配置环境参数,指定配置文件的位置 -->
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <!-- 配置Spring的ContextLoaderListener监听器,初始化Spring容器 -->
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- 配置OpenSessionInViewFilter -->
    <filter>
      <filter-name>OpenSessionInViewFilter</filter-name>
      <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
      <filter-name>OpenSessionInViewFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- Struts2核心控制器 -->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

</web-app>

其中,contextConfigLocation参数用来指定Spring配置文件的路径,经过以上配置就能在Web应用启动的同时初始化Spring容器
如果没有指定contextConfigLocation参数参数,ContextConfigLocation默认会去查找/WEB-INF/applicationContext.xml
换句话就是说,如果将配置文件命名为applicationContext.xml 并保存到WEB-INF目录下,即使不指定ContextConfigLocation参数
也能实现配置文件的加载.

 

S(Spring)S(Struts2)框架整合之配置web.xml文件

原文:http://www.cnblogs.com/AnotherEon001/p/6763453.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!