<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=cduplichien" rel="nofollow">Clark Duplichien</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8178?redirect=false" rel="nofollow">SPR-8178</a></strong> and commented</p>
<p dir="auto">When using RequestMapping annotated controller methods, you can only have have access to the handler method if you have an Errors object as one of the method arguments, and perform error handling within the method.<br>
This is not ideal for use cases where you want to remove boiler plate code and delegate handling of BindExceptions, but need to have access to the method that (would have been) executed. For example, we have an annotation on the controller method indicating what view the bind errors should be displayed on when a BindExcpetion occurs.<br>
Since the annotation is on the controller method, we're currently having to perform some ugly reflection in the HandlerExceptionResolver that handles the BindException in order to extract the controller method for the request from the HandlerAdapter.<br>
It would be preferable if we could have one of:</p>
<ol dir="auto">
<li>The handler method that would have been called exposed in the BindException (or even a subclassed "HandlerMethodBindException" or the like for the case when it fails from HandlerMethodInvoker)</li>
<li>Or the handler method exposed to the HandlerExceptionResolver itself (Though admittedly have no idea how this would work).</li>
<li>Or a (thread-bound) accessor method on AnnotationMethodHandlerAdapter that would return the last resolved controller method.</li>
<li>Or a public method in AnnotationMethodHandlerAdapter that accepts Object handler and HttpServletRequest request, and returns the Method object for the request (what we're currently doing, just with reflection).</li>
</ol>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.3</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398111153" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12776" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12776/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12776">#12776</a> <code class="notranslate">@ExceptionHandler</code> doesn't handle exceptions from other controllers (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/aa7a100807448ea949d69c2e7b8460ce72fea45b/hovercard" href="https://github.com/spring-projects/spring-framework/commit/aa7a100807448ea949d69c2e7b8460ce72fea45b"><tt>aa7a100</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/5309e43ea0fe9b1e18c9b270eacf967546ca13ac/hovercard" href="https://github.com/spring-projects/spring-framework/commit/5309e43ea0fe9b1e18c9b270eacf967546ca13ac"><tt>5309e43</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/f752b47fcbb3b5bfc31e118cda6f8a24a7ae4e6b/hovercard" href="https://github.com/spring-projects/spring-framework/commit/f752b47fcbb3b5bfc31e118cda6f8a24a7ae4e6b"><tt>f752b47</tt></a></p>
<p dir="auto">1 votes, 3 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=eugenparaschiv" rel="nofollow">Eugen Paraschiv</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8124?redirect=false" rel="nofollow">SPR-8124</a></strong> and commented</p>
<p dir="auto">The fact that a method annotated with <code class="notranslate">@ExceptionHandler</code> can only handle exceptions from the same controller is a restrictive issue. The better behavior would be if the annotated method would be able to handle all exceptions of that particular type, regardless of their source.</p>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398105681" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11937" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11937/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11937">#11937</a> <code class="notranslate">@ResponseBody</code> usage limitations (<em><strong>"duplicates"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398111390" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12829" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12829/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12829">#12829</a> Expose handler method when BindException is thrown from HandlerMethodInvoker (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>