2011年9月5日星期一

SpringMVC 配置1

SpringMVC 配置

 

1、 web.xml

<?xmlversion="1.0" encoding="UTF-8"?>

<web-appxmlns="http://java.sun.com/xml/ns/javaee"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

           version="2.5">

 

    <!-- Context Configuration locations forSpring XML files -->

    <context-param>

       <param-name>contextConfigLocation</param-name>

        <param-value>

            classpath:/applicationContext-resources.xml

           classpath:/applicationContext-dao.xml

           classpath:/applicationContext-service.xml

        </param-value>

    </context-param>

    <!--如果不定义webAppRootKey参数,那么webAppRootKey就是缺省的"webapp.root"。但最好设置,

    以免项目之间的名称冲突。

    定义以后,在Web Container启动时将把ROOT的绝对路径写到系统变量里。

    然后log4j的配置文件里就可以用${webName.root }来表示Web目录的绝对路径,把log文件存放于webapp中。

    此参数用于后面的“Log4jConfigListener”-->

    <context-param>

    <param-name>webAppRootKey</param-name>

   <param-value>webapp.root</param-value>

    </context-param>

 

    <!--Spring默认刷新Log4j配置文件的间隔,单位为millisecond-->

    <context-param>

   <param-name>log4jRefreshInterval</param-name>

    <param-value>60000</param-value>

    </context-param>

 

    <!--由Sprng载入的Log4j配置文件位置-->

    <context-param>

       <param-name>log4jConfigLocation</param-name>

       <param-value>/WEB-INF/log4j.properties</param-value>

    </context-param>

 

    <filter>

        <filter-name>encodingFilter</filter-name>

       <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

        <init-param>

           <param-name>encoding</param-name>

           <param-value>UTF-8</param-value>

        </init-param>

        <init-param>

           <param-name>forceEncoding</param-name>

           <param-value>true</param-value>

        </init-param>

    </filter>

 

    <filter-mapping>

       <filter-name>encodingFilter</filter-name>

       <url-pattern>/*</url-pattern>

    </filter-mapping>

    <!--Spring log4j Config loader

       需要放在ContextLoaderListener之前

       否则会提示log4j:WARN No appenders couldbe found for logger (org.springframework.web.context.ContextLoader)

    -->

    <listener>

        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>

    </listener>

    <listener>

       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    <listener>

       <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

    </listener>

 

    <servlet>

       <servlet-name>dispatcher</servlet-name>

       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet-mapping>

       <servlet-name>dispatcher</servlet-name>

       <url-pattern>/</url-pattern>

    </servlet-mapping>

 

    <session-config>

       <session-timeout>10</session-timeout>

    </session-config>

 

    <welcome-file-list>

       <welcome-file>index.jsp</welcome-file>

    </welcome-file-list>

 

    <error-page>

       <error-code>500</error-code>

       <location>/error.jsp</location>

    </error-page>

    <error-page>

        <error-code>400</error-code>

       <location>/index.jsp</location>

    </error-page>

    <error-page>

       <error-code>403</error-code>

       <location>/403.jsp</location>

    </error-page>

    <error-page>

       <error-code>404</error-code>

        <location>/404.jsp</location>

    </error-page>

</web-app>


没有评论:

发表评论