ifeilong / feilong-spring

:gem:focus on spring
Apache License 2.0
4 stars 12 forks source link

SimpleMappingHandlerMethodExceptionResolver 支持 直接 print #165

Closed venusdrogon closed 5 years ago

venusdrogon commented 5 years ago

SimpleMappingHandlerMethodExceptionResolver 支持 直接 print

venusdrogon commented 5 years ago

image

image

venusdrogon commented 5 years ago

第一步 springmvc-pay-notify-exception.xml


<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" xmlns:cache="http://www.springframework.org/schema/cache"
    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
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

    <!-- doku notify异常解决器 -->
    <bean id="dokuNotifyExceptionResolver" class="com.feilong.spring.web.servlet.handler.SimpleMappingHandlerMethodExceptionResolver">
        <property name="order" value="1" />
        <property name="preventResponseCaching" value="true" />
        <property name="mappedHandlerClasses">
            <array>
                <value>com.feilong.psi.doku.controller.notify.DokuNotifyController</value>
            </array>
        </property>

        <property name="exceptionMappings">
            <props>
                <!-- STOP -->
                <prop key="com.feilong.psi.exception.PsiNotifyException">printwrite:STOP</prop>
                <prop key="java.lang.Throwable">printwrite:STOP</prop>

            </props>
        </property>
    </bean>

</beans>

第二步 springmvc-exceptionResolver.xml


<?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:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <import resource="classpath:springmvc/pay/springmvc-pay-channel-exception.xml" />
    <import resource="classpath:springmvc/pay/springmvc-pay-redirect-exception.xml" />
    <import resource="classpath:springmvc/pay/springmvc-pay-notify-exception.xml" />

    <!-- exceptionResolver -->
    <bean id="exceptionResolver" class="com.baozun.exception.ExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <prop key="com.baozun.exception.BusinessException">forward:/errors/error</prop>
                <prop key="java.lang.Throwable">forward:/errors/error</prop>
            </props>
        </property>
    </bean>

</beans>

第三步 springmvc-viewResolver-printwrite.xml


<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:cache="http://www.springframework.org/schema/cache"
    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
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

    <bean class="com.feilong.spring.web.servlet.view.printwriter.PrintWriterViewResolver">
        <property name="order" value="-1" />
        <property name="prefix" value="printwrite:" />
    </bean>

</beans>