码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-04-25 18:29:57      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:apach   spring配置   tsp   配置文件   version   html   loader   nat   控制器   

<?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文件

标签:apach   spring配置   tsp   配置文件   version   html   loader   nat   控制器   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!