springmvc.spring-mvc-exception.xml Maven / Gradle / Ivy
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="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.xsd"> <description>异常处理、错误消息国际化、入参校验、cglib代理</description> <!-- 通知spring使用cglib而不是jdk的来生成代理方法 AOP可以拦截到Controller 这里spring mvc的配置要加,ApplicationContext的配置也要加--> <!-- Aop之所以有的人说拦截不到Controller是因为Controller被jdk代理了。我们只要把它交给cglib代理就可以了。 --> <aop:aspectj-autoproxy proxy-target-class="true" /> <!-- <bean id="exceptionResolver" class="${core.openApi.exceptionResolver:cn.meteor.module.core.openApi.exception.APISimpleMappingExceptionResolver}" init-method="init"> <property name="order" value="-1" /> <property name="defaultErrorView" value="error" /> </bean> --> <!-- <bean id="exceptionResolver" class="cn.meteor.casclient.dzfpapi.exception.APIDzfpSimpleMappingExceptionResolver"> <property name="order" value="-1" /> <property name="defaultErrorView" value="error" /> </bean> --> <bean id="exceptionResolver" class="cn.meteor.module.core.spring.DynamicFactoryBean"> <property name="targetClass" value="${core.openApi.exceptionResolver:cn.meteor.module.core.openApi.exception.APISimpleMappingExceptionResolver}"/> <property name="propertyMap"> <map> <entry key="order" value="-1" /> <entry key="defaultErrorView" value="error" /> </map> </property> </bean> <!-- <bean id="errorMsgUtils" class="${core.openApi.errorMsgUtils:cn.meteor.module.core.openApi.response.ErrorMsgUtils}" lazy-init="false" init-method="init" /> --> <bean id="errorMsgUtils" class="cn.meteor.module.core.spring.DynamicFactoryBean" lazy-init="false"> <property name="targetClass" value="${core.openApi.errorMsgUtils:cn.meteor.module.core.openApi.response.ErrorMsgUtils}"/> <property name="propertyMap"> <map> <entry key="messageSource" value-ref="messageSource" /> </map> </property> </bean> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames" value="${core.openApi.messageSource.basenames:openApi/i18n/error/error}" /> <!-- <property name="basenames"> <list> <value>properties/openApi/i18n/error/error</value> <value>openApi/i18n/error/error</value> </list> </property> --> </bean> <!-- JSR303 Validator定义 --> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/> <!-- 如果不加默认到 使用classpath下的 ValidationMessages.properties --> <property name="validationMessageSource" ref="messageSource"/> </bean> <bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor"> <property name="validator" ref="validator"/> </bean> <!-- <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.Throwable">error/500</prop> </props> </property> </bean> --> </beans>