重大改版
 鱼翔空 2014-07-13 框架封装|   0 868 
文章评分 90 次,平均分 5.0

框架的web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>framework</display-name>
 <context-param>
    <description>配置不登录就可以访问的url</description>
    <param-name>noLoginUrl</param-name>
    <param-value>/tologin,/login,/loginCallBack</param-value>
 </context-param>
  
    <!--
       log4j日志信息的配置,设置在classpath根目录下 ,spring中很多代码使用了不同的日志接口,既有log4j也有commons-logging,
         这里只是强制转换为log4j!并且,log4j的配置文件只能放在classpath根路径。  同时,需要通过commons-logging配置将日志控制权转交给log4j。
         同时commons-logging.properties必须放置  在classpath根路径****** -->  
    <!--******************************* -->  
    <context-param>  
        <param-name>log4jConfigLocation</param-name>  
        <param-value>classpath:log4j.properties</param-value>  
    </context-param>  
      
    <!--Spring默认刷新Log4j配置文件的间隔,单位为millisecond,可以不设置 -->  
    <context-param>  
        <param-name>log4jRefreshInterval</param-name>  
        <param-value>60000</param-value>  
    </context-param> 
  <!-- 设置ServletContext 参数 -->
  <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>classpath:aplicationContext-common.xml;classpath:spring-cxf.xml</param-value>
  </context-param>
  <filter>
    <description>字符集过滤器</description>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <description>字符集编码</description>
      <param-name>encoding</param-name>
      <param-value>utf-8</param-value>
    </init-param>
  </filter>
    <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- 当springmvc 配置的url-pattern为/时,所有的请求资源都会被springmvc处理
             静态资源不需要springmvc处理,写在DispatcherServlet的前面, 让 defaultServlet先拦截,这样就不会进入Spring了
             需要在springmvc-context.xml中写上<mvc:default-servlet-handler />  
        Tomcat, Jetty, JBoss, and GlassFish  默认 Servlet的名字 - "default"
	    Google App Engine 默认 Servlet的名字 - "_ah_default"
		Resin 默认 Servlet的名字 - "resin-file"
		WebLogic 默认 Servlet的名字  - "FileServlet"
		WebSphere  默认 Servlet的名字 - "SimpleFileServlet" 
  
   -->
   <!-- 静态资源都放在了/assets/目录下了,直接拦截目录就可以了 ,也可以具体某些后缀-->
  <servlet-mapping>
       <servlet-name>default</servlet-name>
       <url-pattern>/assets/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
       <servlet-name>default</servlet-name>
       <url-pattern>/demo/*</url-pattern>
  </servlet-mapping>
  <!-- druid内置监控界面使用配置,/druid/index.html页面 -->
  <servlet>
     <servlet-name>DruidStatView</servlet-name>
     <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
  </servlet>
  <servlet-mapping>
     <servlet-name>DruidStatView</servlet-name>
     <url-pattern>/druid/*</url-pattern>
  </servlet-mapping>
  <!-- 配置springmvc -->
  <servlet>
    <description>spring mvc 分发器</description>
    <servlet-name>framework</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
       <!-- spring mvc 配置文件
                            给DispatcherServlet的父类FrameworkServlet属性contextConfigLocation赋值 
                             包含容器启动时所要执行的内容
                             如果不配置init-param参数,在服务器启动时,会在WEB-INF目录下查找命名规则为<servlet-name>-servlet.xml的文件,对应到这里就是framework-servlet.xml文件         
       -->
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath*:springmvc-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
     <servlet-name>framework</servlet-name>
     <url-pattern>/</url-pattern>
  </servlet-mapping>
  
  <!-- DispatcherServlet 会加载ContextLoaderListener  
     如果不继承cxf,可以不加该监听器,
      这里,让ContextLoaderListener加载spring公用方法,和cxf的配置
  -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
 
  <!--  cxf 集成配置 start 
   cxf的spring容器只能由 ContextLoaderListener来启动
  -->
  <servlet>
    <servlet-name>cxf</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>cxf</servlet-name>
    <url-pattern>/webServices/*</url-pattern>
  </servlet-mapping> 
  <!-- cxf 集成配置 end -->
  <!-- 自定义方法,保存系统初始化数据 -->
  <listener>
     <listener-class>com.yxkong.common.utils.CommonServletContextListener</listener-class>
  </listener>
  <!--配置该监听器以后,可以在pojo中获取request
  HttpServletRequest request =((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest()
    -->
  <listener>
     <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>
  <listener>
  <!-- 处理由JavaBean Introspector使用而引起的缓冲泄露, 它是一个在web应用关闭时清除JavaBean Introspector的监听器 -->
  <listener-class>
			org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>
  <session-config>
    <session-timeout>3600</session-timeout>
  </session-config>
  

  <!-- cxf log4j 配置 -->
   <context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>classpath:log4j.properties</param-value>
  </context-param>
  <context-param>
      <param-name>log4jRefreshInterval</param-name>
      <param-value>60000</param-value>
  </context-param>
  <listener>
    <listener-class>
         org.springframework.web.util.Log4jConfigListener
    </listener-class>
 </listener>
  <!-- cxf log4j配置结束 -->
</web-app>


 

除特别注明外,本站所有文章均为我要编程原创,转载请注明出处来自http://5ycode.com/article/22.html

关于
该用户很懒!
切换注册

登录

忘记密码 ?

切换登录

注册

扫一扫二维码分享