<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=mharhen" rel="nofollow">Michael Harhen</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-321?redirect=false" rel="nofollow">SPR-321</a></strong> and commented</p>
<p dir="auto">I have written code to enable initialization of a bean using initialization parameters from a database table. I would be happy to submit the code to the Spring project.</p>
<p dir="auto">In summary, a FactoryBean is specified in an ApplicationContext xml file creates the bean. The bean's properties values are read from a database table. Properties can be reinitialized at any time, using the current values in the database table.</p>
<p dir="auto">The preliminary code can be downloaded from:</p>
<p dir="auto"><a href="http://members.cox.net/jwebutil/InitParameters.zip" rel="nofollow">http://members.cox.net/jwebutil/InitParameters.zip</a></p>
<p dir="auto">I have posted information on how to use it is available on the Spring forum at:<br>
<a href="http://forum.springframework.org/viewtopic.php?t=87" rel="nofollow">http://forum.springframework.org/viewtopic.php?t=87</a></p>
<hr>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/10212/InitParameters.zip" rel="nofollow">InitParameters.zip</a> (<em>145.76 kB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/10211/InitParameters.zip" rel="nofollow">InitParameters.zip</a> (<em>129.53 kB</em>)</li>
</ul>
<p dir="auto">0 votes, 5 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=jkuipers" rel="nofollow">Joris Kuipers</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7820?redirect=false" rel="nofollow">SPR-7820</a></strong> and commented</p>
<p dir="auto">During a consultancy gig this came up: customer wants to be able to throw a custom exception from <code class="notranslate">@Controller</code> methods where the exception will contain an object that needs to be marshalled back to the client as JSON, since these methods respond to AJAX requests and thus the response will not be rendered directly by the browser.<br>
I tried to do this by adding a method to an abstract parent class of the relevant controllers that looked like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@ExceptionHandler(MyCustomValidationErrorsException.class)
@ResponseBody
public MyCustomValidationErrors handleValidationErrors(MyCustomValidationErrorsException e) {
    return e.getValidationErrors();
}"><pre class="notranslate"><code class="notranslate">@ExceptionHandler(MyCustomValidationErrorsException.class)
@ResponseBody
public MyCustomValidationErrors handleValidationErrors(MyCustomValidationErrorsException e) {
    return e.getValidationErrors();
}
</code></pre></div>
<p dir="auto">This prevents regular methods from having to specify <code class="notranslate">Object</code> as the return type, since they would otherwise need to return either a regular domain object or a <code class="notranslate">MyCustomValidationErrors</code> instance in the case of validation errors.</p>
<p dir="auto">However, at the moment <code class="notranslate">@ResponseBody</code> is not supported for <code class="notranslate">@ExceptionHandler</code> methods, so this will simply ignore the annotation and render a view using the default view name resolution algorithm. I think this would be a very useful addition for the sketched use case, so I was wondering if this support could be added to the framework.<br>
I understand that there are other ways to achieve the desired functionality, but AFAICT it would require a relatively large amount of custom code that would duplicate much of the Spring MVC-provided functionality.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</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="398103314" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11567" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11567/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11567">#11567</a> <code class="notranslate">@ResponseBody</code> does not work with <code class="notranslate">@ExceptionHandler</code> (<em><strong>"duplicates"</strong></em>)</li>
</ul>