<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=stuartgunter" rel="nofollow">Stuart Gunter</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9226?redirect=false" rel="nofollow">SPR-9226</a></strong> and commented</p>
<p dir="auto">In certain circumstances, the response is committed before the Interceptor postHandle method is invoked. This appears to be caused when the HandlerMethod is annotated with <code class="notranslate">@ResponseBody</code>.</p>
<p dir="auto">Steps to reproduce:</p>
<ol dir="auto">
<li>Create a Controller method annotated with <code class="notranslate">@ResponseBody</code>.</li>
<li>Configure an Interceptor for this path (or all path mappings)</li>
<li>Submit a request to the path above, with a breakpoint set in the Interceptor's postHandle method.</li>
<li>Check the value of response.isCommitted()</li>
</ol>
<p dir="auto">Expected:<br>
Response should not be committed</p>
<p dir="auto">Actual:<br>
Response is committed.</p>
<p dir="auto">Implications:<br>
Interceptors are unable to modify the response for <code class="notranslate">@ResponseBody</code> HandlerMethods. This prevents Interceptors from being able to add headers to the response.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1.1</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="398216472" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/20595" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/20595/hovercard" href="https://github.com/spring-projects/spring-framework/issues/20595">#20595</a> StringHttpMessageConverter flush out response immediately before execute posthandler (<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="398154729" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14614" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14614/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14614">#14614</a> Make <code class="notranslate">@RequestMapping</code> inject the negotiated MediaType</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398161090" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/15486" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/15486/hovercard" href="https://github.com/spring-projects/spring-framework/issues/15486">#15486</a> Provide better intercepting model for controllers returning <code class="notranslate">@ResponseBody</code> (<em><strong>"is superseded by"</strong></em>)</li>
</ul>
<p dir="auto">2 votes, 7 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=gbilodeau" rel="nofollow">Guillaume Bilodeau</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-3817?redirect=false" rel="nofollow">SPR-3817</a></strong> and commented</p>
<p dir="auto">As discussed here: <a href="http://forum.springframework.org/showthread.php?p=139502" rel="nofollow">http://forum.springframework.org/showthread.php?p=139502</a></p>
<p dir="auto">Given the following context:</p>
<p dir="auto">. an application built with compile-time weaving using AspectJ 1.5.x,<br>
. use of Spring 2.0.x<br>
. a class annotated with <code class="notranslate">@Transactional</code> - not its methods,<br>
. the same class containing one or more setters for dependency injections,<br>
. a Spring application context declaring the above class with a singleton scope and its dependencies through property references<br>
. the same application context using the &lt;tx:annotation-driven /&gt; tag</p>
<p dir="auto">Upon loading the application context and instantiating the annotated class, the container tries to begin a transaction but fails with the following message:</p>
<p dir="auto">java.lang.IllegalStateException: Property 'transactionManager' must be set on transaction aspect</p>
<p dir="auto">The current behavior is understandable: the class was annotated in such a way that all its public methods should be transactional, which includes the DI setters.  However this doesn't seem to be desirable, given the thrown exception.</p>
<p dir="auto">One possible workaround is to annotate only the transactional methods (and so not the DI setter methods) instead of the class itself.  The main drawback is that this leads to the duplication of the annotation and its list of rollback exceptions.  It also requires that all unit tests which operate on the annotated class should provide the AnnotationTransactionAspect a mock PlatformTransactionManager on setUp().</p>
<p dir="auto">One possible solution would be to activate the transactional aspect only after the application context is loaded.  Another one would be to introduce a <code class="notranslate">@NotTransactional</code> annotation that would override the class annotation and that could be used on DI setter methods.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.6</p>
<p dir="auto">2 votes, 7 watchers</p>