开发者

How to send exceptions to exceptionController?

<bean
    class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    <property name="mappedHandlers">
        <set>
            <ref bean="exceptionController" />
        </set>
    </property>
    <property name="defaultErrorView" value="tiles/content/error" />
</bean>

I'm trying to send exceptions to a co开发者_如何学运维ntroller so I can create a redirect. If I comment out the mappedHandlers part then the error tile is displayed but it is only a tile. The rest of the tiles load normally. I need to make a redirect in the controller so I can show an error page not just an error tile.

I can't find enough information or an example how the exception invokes some method in exceptionController.


You're misunderstanding what the mappedHandlers property is for. This is saying that this exception resolver bean should only apply to exceptions thrown by the controllers listed in that property. It does not send the exceptions to that controller.

If you want to send a simple redirect, then you can do somrthing like this:

<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    <property name="defaultErrorView" value="redirect:/myErrorPage" />
</bean>

You will lose all information on the exception by doing this, though.

If you want to write custom code to handle exceptions, then I suggest writing your own implementation of HandlerExceptionResolver (probably a subclass of AbstractHandlerExceptionResolver), and using that instead of SimpleMappingExceptionResolver.

Another alternative is to use the @ExceptionHandler annotation style (see docs here).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜