<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=cnichols" rel="nofollow">Christopher Nichols</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7584?redirect=false" rel="nofollow">SPR-7584</a></strong> and commented</p>
<p dir="auto">Lightly wordsmithing the original post from the forum.</p>
<p dir="auto">"We recently upgraded from Spring 2.5.6 to Spring 3.0.2. We had "default-lazy-init" set to true for the majority of the beans and didn't change those settings with our Spring upgrade. However, we found that the lazy-init behavior changed between Spring 2.5 and 3.0.</p>
<p dir="auto">With 2.5, the beans flagged for lazy-init are truly lazily initialized, i.e. they are initialized on demand after the Spring Application Context instantiation is complete.</p>
<p dir="auto">With 3.0, the Spring container attempts to eagerly initiate all beans including the ones flagged for lazy-init, as part of the Spring Application Context instantiation step. If any bean flagged for lazy-init throws exception during initialization, the exception will be ignored and Spring Application Context instantiation will continue on..."  See the forum post for more details.</p>
<p dir="auto">The upgrade guide doesn't have any details about lazy-init changing the way it functions.  As such, this looks a bug.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.2</p>
<p dir="auto"><strong>Reference URL:</strong> <a href="http://forum.springsource.org/showthread.php?p=318697#post318697" rel="nofollow">http://forum.springsource.org/showthread.php?p=318697#post318697</a></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="398112342" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12992" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12992/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12992">#12992</a> Lazy-init beans are unnecessarily created during the candidate determination process (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=gobreak" rel="nofollow">gobreak</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2181?redirect=false" rel="nofollow">SPR-2181</a></strong> and commented</p>
<p dir="auto">I have tried using JBossMQ and ActiveMQ to receive async message by DefaultMessageListenerContainer.<br>
Transaction Manager from JBoss are used and set properly as a bean property for DefaultMessageListenerContainer.<br>
To trigger the XA rollback, I throw a runtime exception in the onMessage() callback of the MessageListener.<br>
However, the message is still commit.</p>
<p dir="auto">The bean setting:<br>
&lt;bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt;<br>
&lt;property name="userTransaction" ref="userTransaction"/&gt;<br>
&lt;/bean&gt;</p>
<p dir="auto">&lt;bean id="userTransaction"<br>
class="org.springframework.jndi.JndiObjectFactoryBean"&gt;<br>
&lt;property name="jndiName"&gt;<br>
&lt;value&gt;java:comp/UserTransaction&lt;/value&gt;<br>
&lt;/property&gt;<br>
&lt;/bean&gt;</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;bean id=&quot;listenerContainer&quot;
        class=&quot;org.springframework.jms.listener.DefaultMessageListenerContainer&quot;&gt;
        &lt;property name=&quot;connectionFactory&quot; ref=&quot;XAJmsConnectionFactory&quot; /&gt;
        &lt;property name=&quot;destination&quot; ref=&quot;XADestination&quot; /&gt;
        &lt;property name=&quot;messageListener&quot; ref=&quot;coreInboundBeanImpl&quot; /&gt;
        &lt;property name=&quot;transactionManager&quot; ref=&quot;transactionManager&quot;/&gt;
&lt;/bean&gt;"><pre class="notranslate"><code class="notranslate">&lt;bean id="listenerContainer"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer"&gt;
        &lt;property name="connectionFactory" ref="XAJmsConnectionFactory" /&gt;
        &lt;property name="destination" ref="XADestination" /&gt;
        &lt;property name="messageListener" ref="coreInboundBeanImpl" /&gt;
        &lt;property name="transactionManager" ref="transactionManager"/&gt;
&lt;/bean&gt;
</code></pre></div>
<p dir="auto">Finally, I needed to extend DefaultMessageListenerContainer and override the receive() method using JMSTemplate instead of the message consumer as follow:<br>
public Message receive(long timeOut) throws JMSException{<br>
template.setConnectionFactory(getConnectionFactory());<br>
template.setDefaultDestination(getDestination());<br>
template.setReceiveTimeout(timeOut);<br>
if (getMessageSelector() == null || "".equals(getMessageSelector().trim()))<br>
return template.receive(getDestination());<br>
else<br>
return template.receiveSelected(getDestination(), getMessageSelector());<br>
}</p>
<p dir="auto">I use JMSTemplate because I find it performs XA without any noticed problem.<br>
Using the above implementation can successfully rollback as well as commit the message. I am seeking for better solution on this topic.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0 RC1</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="398066706" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/6784" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/6784/hovercard" href="https://github.com/spring-projects/spring-framework/issues/6784">#6784</a> Cannot do XA Rollback Using DefaultMessageListenerContainer on JBoss (<em><strong>"duplicates"</strong></em>)</li>
</ul>