1、web.xml
2、rest-servlet.xml
3、interceptor-servlet.xml
4、log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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元素包含的就是XML编辑器显示的名称 -->
<display-name>Archetype Created wqo Web Application</display-name>
<!--
Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔
此参数用于后面的Spring-Context loader
-->
<context-param>
<param-name>contextCongfigLocation</param-name>
<param-value>
classpath*:spring/*.xml
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.xml</param-value>
</context-param>
<!-- ContextLoaderListener预设会读取applicationContext.xml,
您可以指定自己的定义档,只要在<context-param>中指定"contextConfigLocation"参数 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Log4jConfigListener 允许您通过 log4jConfigLocation Servlet
上下文参数显式指定 Log4J 配置文件的地址 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- 所有filter,委托给spring -->
<filter>
<filter-name>appFilters</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>appFilters</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>etagFilter</filter-name>
<filter-class>org.springframework.web.filter.ShallowEtagHeaderFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>etagFilter</filter-name>
<servlet-name>/*</servlet-name>
</filter-mapping>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
<!-- 配置文件名 -->
/WEB-INF/rest-servlet.xml,
/WEB-INF/interceptor-servlet.xml,
/WEB-INF/controller-servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>1000</session-timeout>
</session-config>
<!-- 错误页面定义 -->
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/jsp/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/jsp/500.jsp</location>
</error-page>
</web-app>
2、rest-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byName"
xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:config/*.properties</value>
</list>
</property>
</bean>
<!-- Default View Resolver -->
<bean id="internalResourceViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="1"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- jackson专门的视图MappingJacksonJsonView配置,完成转换json -->
<bean id="jsonView"
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="encoding">
<value type="org.codehaus.jackson.JsonEncoding">UTF8</value>
</property>
<property name="contentType" value="application/json;charset=UTF-8" />
</bean>
<!-- 实现类似拦截器的功能 -->
<bean id="hostUserArgumentResolver" class="com.xiaonei.wap.spring.mvn.resolver.HostUserArgumentResolver" />
<!-- 实现RESTful URL映射,为了实现方法级别的注解,就需要确保DefaultAnnotationHandlerMapping
和AnnotationMethodHandlerAdapter同时被定义 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="customArgumentResolver" ref="hostUserArgumentResolver" />
<property name="messageConverters">
<util:list id="beanList">
<ref bean="mappingJacksonHttpMessageConverter" />
</util:list>
</property>
</bean>
<!-- 能够将POJO对象自动转换为JSON对象 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<!-- url mapping by bean name 实现类型级别的注解-->
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="0" />
</bean>
<!-- Default ExceptionHandler -->
<bean id="defaultExceptionHandler" class="com.xiaonei.wap.spring.mvc.resolvers.RestExceptionResolver">
<property name="defaultErrorView" value="error" />
<property name="defaultStatusCode" value="500" />
</bean>
</beans>
3、interceptor-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byName"
xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- 会为每一个HandlerMapping,注入一个拦截器 ,起到总拦截器的作用-->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="com.xiaonei.wap.spring.mvc.interceptors.AutorizeInterceptor"/>
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="com.xiaonei.wap.spring.mvc.interceptors.DefaultViewInterceptor" />
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="com.xiaonei.wap.spring.mvc.inteceptors.CommonInterceptor" />
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="com.xiaonei.wap.spring.mvc.interceptors.LogInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
</beans>
4、log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- 设置通道ID:wapstdout和输出方式:org.apache.log4j.DailyRollingFileAppender -->
<!-- DailyRollingFileAppender 每天产生一个日志文件 -->
<!-- 配置输出目的地Appender Appender主要定义日志信息输出在什么位置 -->
<appender name="wapstdout" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${catalina.base}/logs/fuxi/wap_stdout.log" />
<!-- 日志文件时间后缀 -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<!-- 输出文本的样式 -->
<layout class="org.apache.log4j.PatternLayout">
<!-- log的显示格式 -->
<param name="ConversionPattern" value="%d{yyyy-MM-dd-HH:mm:ss,SSS} %5p - %m%n">
</layout>
</appender>
<appender name="stdout" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${catalina.base}/logs/fuxi/stdout.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd-HH:mm:ss,SSS} %5p - %m%n" />
</layout>
</appender>
<appender name="wap404log" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${catalina.base}/logs/fuxi/wap404.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd-HH:mm:ss,SSS} %5p - %m%n" />
</layout>
</appender>
<appender name="wap500log" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${catalina.base}/logs/fuxi/wap500.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd-HH:mm:ss,SSS} %5p - %m%n" />
</layout>
</appender>
<appender name="useraccessLogAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${catalina.base}/logs/fuxi/useraccess.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd_HH" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>
<appender name="useraccessRemoteLogAppender"
class="com.xiaonei.wap.framework.log.impl.RemoteLogger2Appender">
<param name="iceArgs" value="WapRemoteLogger2:tcp -h 10.3.19.155 -p 10000" />
<param name="remoteLoggerName" value="fuxi_useraccess" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>
<appender name="useractionLogAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${catalina.base}/logs/fuxi/useraction.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd_HH" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>
<appender name="useractionRemoteLogAppender"
class="com.xiaonei.wap.framework.log.impl.RemoteLogger2Appender">
<param name="iceArgs" value="WapRemoteLogger2:tcp -h 10.3.19.155 -p 10000" />
<param name="remoteLoggerName" value="fuxi_useraction" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>
<!-- 设置域名限制,即wap404logger域及以下的日志均输出到下面对应的通道中 -->
<logger name="wap404logger" additivity="false">
<!-- 设置级别 -->
<level value="info" />
<!-- 与前面的通道id相对应 -->
<appender-ref ref="wap404log" />
</logger>
<logger name="wap500logger" additivity="false">
<level value="info" />
<appender-ref ref="wap500log" />
</logger>
<logger name="useraccessLogger" additivity="false">
<level value="info" />
<appender-ref ref="useraccessLogAppender" />
</logger>
<logger name="useraccessRemoteLogger" additivity="false">
<level value="info" />
<appender-ref ref="useraccessRemoteLogAppender" />
</logger>
<logger name="localuseraction" additivity="false">
<level value="info" />
<appender-ref ref="useractionLogAppender" />
</logger>
<logger name="useraction" additivity="false">
<level value="info" />
<appender-ref ref="useractionRemoteLogAppender" />
</logger>
<logger name="org.springframework" additivity="false">
<level value="error" />
<appender-ref ref="stdout" />
</logger>
<logger name="com.renren.wap.fuxi" additivity="false">
<level value="debug" />
<appender-ref ref="wapstdout" />
</logger>
<logger name="com.xiaonei" additivity="false">
<level value="error" />
<appender-ref ref="wapstdout" />
</logger>
<!-- 设置接收所有输出的通道 -->
<root>
<level value="error" />
<!-- 与前面的通道id相对应 -->
<appender-ref ref="stdout" />
</root>
</log4j:configuration>