<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>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=gbrehmer" rel="nofollow">Gerrit Brehmer</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7278?redirect=false" rel="nofollow">SPR-7278</a></strong> and commented</p>
<p dir="auto">The recommended way to develop REST-style webservices is the usage of <code class="notranslate">@ResponseBody</code> annotation and HttpMessageConverter instead of generating a model and a view (ContentNegotiatingViewResolver etc.).<br>
But there are some limitations, that make things hard to handle:</p>
<ul dir="auto">
<li>ExceptionResolver support
<ul dir="auto">
<li><code class="notranslate">@RequestBody</code> is only supported with <code class="notranslate">@ExceptionHandler</code> annotation. I need a centralized exception handling to generate a special error object as the return value. So I must wrote a method in each controller class to delegate to the centralized exception handler. I think the ExceptionResolver-interface is more like an AOP-approach, with no glue code.</li>
<li>ExceptionResolver also have some nice standard implementations like SimpleMappingExceptionResolver, where I can handle the returned HTTP status code very easy. This is also not supported by <code class="notranslate">@ExceptionHandler</code> out of the box</li>
</ul>
</li>
<li>'useNotAcceptableStatusCode' from ContentNegotiatingViewResolver (so for some features, I must also configure view-handling)
<ul dir="auto">
<li>simple and easy to use attribute to enable NOT_ACCEPTABLE Http Status code</li>
</ul>
</li>
<li>missing option for enabling global <code class="notranslate">@ResponseBody-like</code> handling instead of annotate all methods (e.g. in AnnotationMethodHandlerAdapter)</li>
</ul>
<p dir="auto">I also would recommend the full HttpMessageConverter way (<code class="notranslate">@RequestBody</code> &amp; <code class="notranslate">@ResponseBody</code>) without view handling, so it would be nice, if <code class="notranslate">@ResponseBody</code> has fewer limitations. Additionaly it would be great, if the documentation have some notes about the recommended way for webservice-only REST-style applications (with hints to the limitations above)</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.2</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>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398106106" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12012" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12012/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12012">#12012</a> Add equivalent of JAX-RS <code class="notranslate">@Produces</code> to Spring MVC</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/e5eceafa3f31f80177b24db255ca96a252ae9fb1/hovercard" href="https://github.com/spring-projects/spring-framework/commit/e5eceafa3f31f80177b24db255ca96a252ae9fb1"><tt>e5eceaf</tt></a></p>
<p dir="auto">1 votes, 2 watchers</p>