views:

70

answers:

1
<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 controller 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.

+1  A: 

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).

skaffman