spring mvc xml文件配置

<?xml version="1.0" encoding="UTF-8"?>
<!-- ~ Copyright (c) 2014 jon -->


<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


<!-- 配置静态资源,直接映射到对应的文件夹,不被DispatcherServlet处理 -->
<!-- <resources mapping="/images/**" location="/images/" /> <resources mapping="/css/**" 
location="/css/" /> <resources mapping="/js/**" location="/js/" /> <resources 
mapping="/html/**" location="/html/" /> <resources mapping="/common/**" location="/common/" 
/> -->
<!-- AOP 拦截 -->
<beans:import resource="classpath*:config/spring-mvc-aop.xml"/>
<!-- 控制类扫描 -->
<!-- 加载controller的时候,不加载service,因为此时事物并未生效,若此时加载了service,那么事物无法对service进行拦截 -->
<context:component-scan base-package="com.wdp.*.controller,com.wdp.*.core.controller,com.*.*.controller,com.*.*.*.controller,com.*.*.*.*.controller">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>

<!--启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<annotation-driven></annotation-driven>
<!--对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<beans:property name="contentType" value="text/html" />
<!-- <beans:property name="prefix" value="/" /> -->
<beans:property name="prefix" value="/WEB-INF/view/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<!-- 上传文件 -->
<beans:bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<beans:property name="defaultEncoding" value="utf-8"></beans:property>
<!-- 100M -->
<beans:property name="maxUploadSize" value="104857600"></beans:property>
</beans:bean>
<!-- 国际化资源文件 -->
<beans:bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<beans:property name="basename" value="i18n/messages"></beans:property>
</beans:bean>


<!-- 方言 -->
<!-- <beans:bean id="dialect" class="com.wdp.framework.hibernate.dialect.DialectFactoryBean">
<beans:property name="dbType" value="${jdbc.dbType}" />
</beans:bean> -->


<!-- 异常处理类 -->
<beans:bean id="exceptionHandler" class="com.wdp.framework.exception.MyExceptionHandler" />


<!--Web异常解析处理 -->
<beans:bean class="com.wdp.exception.WdpHandlerExceptionResolver">
<beans:property name="order" value="0" />
<!-- 定义默认的异常处理页面,当该异常类型的注册时使用 -->
<beans:property name="defaultErrorView" value="500" /> <!-- 默认为500,系统错误(error.jsp) -->
<beans:property name="defaultStatusCode" value="400" />
<beans:property name="statusCodes"><!-- 配置多个statusCode -->
<beans:props>
<beans:prop key="error/500">500</beans:prop>  <!--500.jsp -->
<beans:prop key="error/404">404</beans:prop> <!-- 404.jsp -->
<beans:prop key="error/401">401</beans:prop> <!-- 401.jsp -->
<beans:prop key="error/403">403</beans:prop> <!-- 403.jsp -->
</beans:props>
</beans:property>
<!-- 定义异常处理页面用来获取异常信息的变量名,默认名为exception -->
<beans:property name="exceptionAttribute" value="ex" />
<!-- 定义需要特殊处理的异常,用类名或完全路径名作为key,异常页名作为值 -->
<beans:property name="exceptionMappings">
<beans:props>
<!-- 这里你可以根据需要定义N多个错误异常转发 -->
<beans:prop key="com.wdp.exception.JsonResponseException">/error/pageError</beans:prop>
<!-- 参数类型有误(pageError.jsp) -->
<beans:prop key="org.springframework.validation.BindException">/error/pageError</beans:prop>
<!-- 数据库错误(pageError.jsp) -->
<beans:prop key="java.sql.SQLException">/error/pageError</beans:prop>
<!-- 参数绑定错误(如:必须参数没传递)(bizError.jsp) -->
<beans:prop key="org.springframework.web.bind.ServletRequestBindingException">/error/pageError</beans:prop>
<!-- 参数错误(bizError.jsp) -->
<beans:prop key="java.lang.IllegalArgumentException">/error/pageError</beans:prop>
<!-- 其他错误为'未定义错误'(unknowError.jsp)  -->
<beans:prop key="java.lang.Exception">/error/pageError</beans:prop>
</beans:props>
</beans:property>
</beans:bean>


<!--启动Spring MVC的注解功能,设置编码方式,防止乱码 -->
<beans:bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<beans:property name="messageConverters">
<beans:list>
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<beans:bean
class="org.springframework.http.converter.StringHttpMessageConverter">
<beans:property name="supportedMediaTypes">
<beans:list>
<beans:value>text/html;charset=UTF-8</beans:value>
</beans:list>
</beans:property>
</beans:bean>
</beans:list>
</beans:property>
</beans:bean>
<!--完成json自动转换的映射  -->
<beans:bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<beans:property name="supportedMediaTypes" value="application/json" />
</beans:bean>
<beans:bean id="formHttpMessageConverter"
class="org.springframework.http.converter.FormHttpMessageConverter" />
<beans:bean id="stringHttpMessageConverter"
class="org.springframework.http.converter.StringHttpMessageConverter" />
<beans:bean id="marshallerHttpMessageConverter"
class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<beans:property name="marshaller" ref="rdpShaller" />
<beans:property name="unmarshaller" ref="rdpShaller" />
</beans:bean>


<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射, 配置一个基于注解的定制的WebBindingInitializer, 
解决日期转换问题,方法级别的处理器映射 -->
<beans:bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<beans:property name="cacheSeconds" value="0" />
<beans:property name="messageConverters">
<beans:list>
<beans:ref bean="mappingJacksonHttpMessageConverter" /><!-- 
json转换器 -->
<beans:ref bean="stringHttpMessageConverter" />
<beans:ref bean="marshallerHttpMessageConverter" />
</beans:list>
</beans:property>
<beans:property name="webBindingInitializer">
<beans:bean class="com.wdp.framework.interceptors.MyWebBinding" />
</beans:property>
</beans:bean>


<!-- spring rest -->
<beans:bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<beans:property name="order" value="1" />
<beans:property name="defaultContentType" value="text/html" />
<beans:property name="mediaTypes">
<beans:map>
<beans:entry key="json" value="application/json" />
<beans:entry key="xml" value="application/xml" />
</beans:map>
</beans:property>
<beans:property name="defaultViews">
<beans:list>
<!-- for application/json -->
<beans:bean
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<beans:property name="objectMapper" ref="rdpMapper" />
</beans:bean>
<!-- for application/xml -->
<beans:bean
class="org.springframework.web.servlet.view.xml.MarshallingView">
<beans:property name="marshaller" ref="rdpShaller" />
</beans:bean>
</beans:list>
</beans:property>
</beans:bean>
<!-- 重新设置 objectMapper -->
<beans:bean id="rdpMapper" class="org.codehaus.jackson.map.ObjectMapper">
<!-- 设置objectMapper的serializationConfig的serializationInclusion属性,以忽略null对象 -->
<beans:property name="serializationConfig.serializationInclusion">
<beans:value
type="org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion">NON_NULL</beans:value>
</beans:property>
</beans:bean>


<!-- 重新设置 marshaller -->
<beans:bean id="rdpShaller" name="rdpShaller"
class="org.springframework.oxm.castor.CastorMarshaller">
<beans:property name="validating" value="false" />
</beans:bean>


<!-- 拦截器 -->

<interceptors>
<interceptor>
 <mapping path="/*.shtml"/>
<beans:bean class="com.wdp.framework.interceptors.EncodingInterceptor" />
</interceptor>
<!-- <interceptor>
<mapping path="/*.shtml"/>
<bean class="org.jeecgframework.core.interceptors.AuthInterceptor">
<property name="excludeUrls">
<list>
<value>loginController.do?goPwdInit</value>
<value>loginController.do?pwdInit</value>
<value>loginController.do?login</value>
<value>loginController.do?checkuser</value>
<value>systemController.do?saveFiles</value>
<value>tFinanceController.do?saveFiles</value>
<value>systemController.do?saveNews</value>
<value>iconController.do?saveIcon</value>
<value>userController.do?savesign</value>
<value>jpPersonController.do?importExcel</value> for:[119]excel导入风格统一
<value>jeecgBlobDataController.do?upload</value> for:[83]Blob型数据例子
<value>cgformFtlController.do?saveWordFiles</value>表单模板上传火狐拦截问题
<value>excelTempletController.do?importExcel</value>表单模板上传火狐拦截问题
<value>repairController.do?repair</value>
<value>repairController.do?deleteAndRepair</value>
</list>
</property>
</bean>
</interceptor> -->
</interceptors>

</beans:beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值