Skip to content

Instantly share code, notes, and snippets.

@relax-more
Created June 4, 2013 08:32
Show Gist options
  • Save relax-more/5704492 to your computer and use it in GitHub Desktop.
Save relax-more/5704492 to your computer and use it in GitHub Desktop.
[java][spring] @ExceptionHandler が利用できなくてハマったので調査した
AnnotationMethodHandlerExceptionResolverの追加が必要。
今回の自分のケースでは、SimpleMappingExceptionResolverを既に利用していたので、 ExceptionResolver の優先順位付けをして、
AnnotationMethodHandlerExceptionResolver を優先度高く設定する必要があった。
詳しくは下記
http://forum.springsource.org/showthread.php?102713-Spring-Web-MVC-ExceptionHandler-ignore-when-exceptionResolver-in-place&p=347448#post347448
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" p:defaultErrorView="uncaughtException">
<property name="exceptionMappings">
<props>
<prop key=".DataAccessException">dataAccessFailure</prop>
<prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</prop>
<prop key=".TypeMismatchException">resourceNotFound</prop>
<prop key=".MissingServletRequestParameterException">resourceNotFound</prop>
</props>
</property>
</bean>
<!-- important p:order="1" and p:order="2"-->
<!-- and AnnotationMethodHandlerExceptionResolver -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver" p:order="1" />
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" p:order="2" p:defaultErrorView="uncaughtException">
<property name="exceptionMappings">
<props>
<prop key=".DataAccessException">dataAccessFailure</prop>
<prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</prop>
<prop key=".TypeMismatchException">resourceNotFound</prop>
<prop key=".MissingServletRequestParameterException">resourceNotFound</prop>
</props>
</property>
</bean>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment