<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=snicoll" rel="nofollow">Stéphane Nicoll</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9684?redirect=false" rel="nofollow">SPR-9684</a></strong> and commented</p>
<p dir="auto">The spring test infrastructure no longer honour prototype-scoped beans if they are injected wiht <code class="notranslate">@Resource</code>. It does work with <code class="notranslate">@Autowired</code>.</p>
<p dir="auto">We suspect that <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398117629" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13814" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13814/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13814">#13814</a> may have brought this regression.</p>
<p dir="auto">To reproduce, extract the zip and run the tests (either from your IDE or on the command line with Maven). You can validate the regression by running the following command:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="mvn clean install -Dspring.version=3.1.1.RELEASE"><pre class="notranslate"><code class="notranslate">mvn clean install -Dspring.version=3.1.1.RELEASE
</code></pre></div>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1.2</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/20192/inject-regression-showcase.zip" rel="nofollow">inject-regression-showcase.zip</a> (<em>6.16 kB</em>)</li>
</ul>
<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="398152030" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14261" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14261/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14261">#14261</a> Regression: scoped beans being cached too aggressively (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">1 votes, 2 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=sam_bernet" rel="nofollow">Samuel Bernet</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9627?redirect=false" rel="nofollow">SPR-9627</a></strong> and commented</p>
<p dir="auto">The bugfix <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398117629" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13814" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13814/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13814">#13814</a> "Scoped-proxy memory leak w/ <code class="notranslate">@Resource</code> injection" leads to bean instances being cached too eagerly in <code class="notranslate">CommonAnnotationBeanPostProcessor</code>. Besides the (desired) caching of AOP scoped-proxies to prevent the memory leak the current code also caches custom scoped bean instances that should not be cached. This happens for example if client code uses <code class="notranslate">AutowireCapableBeanFactory#autowireBean(Object)</code> to inject dependencies (annotation-based) into a manually created bean. In this case no AOP proxies are involved but the cached instances are still used. The underlying scope is never consulted and can thus never signalize that a new instance is to be created and injected because the context of the scope (e.g. request, session) is different from the first call which resulted in the cached instance.</p>
<p dir="auto">I attached a Test-Case (JUnit 4 Test, requires JUnit and Spring to run). The test-case illustrates the breaking change:</p>
<ul dir="auto">
<li>Runs fine with Spring version 3.1.1 and older (tested with 3.0.5)</li>
<li>Fails with Spring version 3.1.2 and 3.2.M1</li>
<li>The defect was introduced in the bugfix for <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398117629" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13814" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13814/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13814">#13814</a> in version 3.2.M1 with commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/f779c199ea272cf61781e120b1ab2efc50de0cbb/hovercard" href="https://github.com/spring-projects/spring-framework/commit/f779c199ea272cf61781e120b1ab2efc50de0cbb"><tt>f779c19</tt></a></li>
<li>The defect was back-ported to version 3.1.2 with <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398118859" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14000" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14000/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14000">#14000</a></li>
</ul>
<p dir="auto">I understand this calling pattern is not very common but nevertheless the affected API is public and our framework relies on this to provide service beans to instances of "visual" classes (a visual models a single page in a web application). This basically renders custom scoped beans (also being used heavily) unusable for us in releases &gt; 3.1.1, thus my classification as "major".</p>
<p dir="auto">Best regards<br>
Samuel Bernet<br>
MSc ETH Software Engineering<br>
<a href="mailto:samuel.bernet@raiffeisen.ch">samuel.bernet@raiffeisen.ch</a></p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1.2, 3.2 M1</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/20123/SPR-9176-TestCase.zip" rel="nofollow">SPR-9176-TestCase.zip</a> (<em>3.29 kB</em>)</li>
</ul>
<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="398152449" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14318" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14318/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14318">#14318</a> <code class="notranslate">@Resource</code> injection regression with scope prototype (<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="398117629" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13814" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13814/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13814">#13814</a> Scoped-proxy memory leak w/ <code class="notranslate">@Resource</code> injection</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398151713" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14214" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14214/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14214">#14214</a> Injecting prototypes into tests using <code class="notranslate">@Resource</code> appears to be broken</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398118859" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14000" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14000/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14000">#14000</a> Backport "Scoped-proxy memory leak w/ <code class="notranslate">@Resource</code> injection"</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398153826" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14485" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14485/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14485">#14485</a> <code class="notranslate">@Resource</code> injection of singleton in prototype using AnnotationConfigApplicationContext is not thread-safe</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/04af54ad4cd7ac335d275487b19e96ed3335f221/hovercard" href="https://github.com/spring-projects/spring-framework/commit/04af54ad4cd7ac335d275487b19e96ed3335f221"><tt>04af54a</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/26ee0c4842ca83dec213b5422d0af18ba2e3ce6c/hovercard" href="https://github.com/spring-projects/spring-framework/commit/26ee0c4842ca83dec213b5422d0af18ba2e3ce6c"><tt>26ee0c4</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/68c5f20bc7891ef9435ffc096e97f626277d27a7/hovercard" href="https://github.com/spring-projects/spring-framework/commit/68c5f20bc7891ef9435ffc096e97f626277d27a7"><tt>68c5f20</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/19718700cf5a99e8e10af5d11d8005835838ddba/hovercard" href="https://github.com/spring-projects/spring-framework/commit/19718700cf5a99e8e10af5d11d8005835838ddba"><tt>1971870</tt></a></p>
<p dir="auto">1 votes, 5 watchers</p>