Handling Exceptions in Spring MVC with Logging

In your Spring servlet.xml, add a HandlerExceptionResolver.

	<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
		<property name="exceptionMappings">
				<prop key="java.lang.Exception">/error/default</prop>
		<property name="defaultErrorView" value="/error/default" />
		<property name="warnLogCategory" value="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" />

“/error/default” is the URL it will go to that will display an error message to the user. warnLogCategory is the logger category. Exceptions will be logged under the warning level and not the error level. The category value can be anything. Here we just set it to the full name of SimpleMappingExceptionResolver.

Spring HandlerExceptionResolver won’t handle errors in the view, so capture these using web.xml



  1. naveen says:

    I tried with property “warnLogCategory” for exception logging..

    No exception being logged in the log file.. Do we need to do specific configuration in log4u.properties file ?
    please suggest.

Leave a Reply

Your email address will not be published. Required fields are marked *