<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Using ejb-jar.xml for @Singleton bean
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/benoit.heinrich">Benoit Heinrich</a> in <i>EJB3</i> - <a href="http://community.jboss.org/message/586995#586995">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi everyone,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I'm new to EJB3.1 and I'm not sure if I'm posting the question to the right forum, so be nice with me to redirect me to the right section if you think it's not ok here.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I'm converting an old jboss @Service (that was running on jboss 4.2.3) to the new @Singleton pattern that I'm deploying to jboss 6.0.0.Final.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My singleton has a lot of dependencies to a lot of beans and to prevent to workaround the issue with dependency resolution for transitive relationships (<a class="jive-link-external-small" href="https://issues.jboss.org/browse/EJBTHREE-2227" style="font-size: 12px; outline-style: none; color: #355491;" target="_blank">https://issues.jboss.org/browse/EJBTHREE-2227</a>) I've moved my Singleton to a separate ear file and then I've set my ears to deploy the one after the other.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Both ears are using the same jboss-app.xml to share the same classloader and I've got two deployment scenario where one work and the other fails.</p><p>&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;</p><p>&amp;lt;!DOCTYPE jboss-app PUBLIC</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; "-//JBoss//DTD Java EE Application 5.0//EN"</p><p><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160; "</span><a class="jive-link-external-small" href="http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd" target="_blank">http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd</a><span>"&amp;gt;</span></p><p>&amp;lt;jboss-app&amp;gt;</p><p>&#160; &amp;lt;loader-repository&amp;gt;</p><p>&#160;&#160;&#160; com.example:loader=01-services</p><p>&#160;&#160;&#160; &amp;lt;loader-repository-config&amp;gt;java2ParentDelegation=false&amp;lt;/loader-repository-config&amp;gt;</p><p>&#160; &amp;lt;/loader-repository&amp;gt;</p><p>&amp;lt;/jboss-app&amp;gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>To reproduce the problem I've created a small example:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>Scenario 1, no ejb-jar.xml</strong></p><p>Here I'm not using ejb-jar.xml and I'm setting the lookup name inside the @EJB annotation</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><code><p><br/>package com.example.services.startup;<br/><br/>import com.example.services.version.VersionManager;<br/>import org.apache.commons.logging.Log;<br/>import org.apache.commons.logging.LogFactory;<br/><br/>import javax.annotation.PostConstruct;<br/>import javax.ejb.EJB;<br/>import javax.ejb.Singleton;<br/>import javax.ejb.Startup;<br/><br/>@Singleton<br/>@Startup<br/>public class StartupBean {<br/>&#160;&#160;&#160; private static final Log log = LogFactory.getLog(StartupBean.class);<br/><br/>&#160;&#160;&#160; @EJB(lookup = "01-services/VersionManagerBean/local")<br/>&#160;&#160;&#160; private VersionManager versionManager;<br/><br/>&#160;&#160;&#160; @PostConstruct<br/>&#160;&#160;&#160; public void startup() {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.info("System started (version " + versionManager.getVersion() + ")");<br/>&#160;&#160;&#160; }<br/>}<br/></p></code></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>When I deploy this to jboss 6 it sucessfully logs the message and so:</p><p><span style="text-decoration: underline;">This one works</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>Scenario 2, jndi mapping done through ejb-jar.xml</strong></p><p>In this scenario I've got the same @Singleton bean but now the @EJB is using a name to reference the ejb from the ejb-jar.xml</p><pre class="jive_text_macro jive_macro_wiki"><p>&lt;code&gt;</p><p>package com.example.services.startup;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import com.example.services.version.VersionManager;</p><p>import org.apache.commons.logging.Log;</p><p>import org.apache.commons.logging.LogFactory;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import javax.annotation.PostConstruct;</p><p>import javax.ejb.EJB;</p><p>import javax.ejb.Singleton;</p><p>import javax.ejb.Startup;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>@Singleton</p><p>@Startup</p><p>public class StartupBean {</p><p>&#160;&#160;&#160; private static final Log log = LogFactory.getLog(StartupBean.class);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @EJB(name = "ejb/VersionManager")</p><p>&#160;&#160;&#160; private VersionManager versionManager;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @PostConstruct</p><p>&#160;&#160;&#160; public void startup() {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.info("System started (version " + versionManager.getVersion() + ")");</p><p>&#160;&#160;&#160; }</p><p>}</p><p>&lt;/code&gt;</p></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> And here is the ejb-jar.xml:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="text-decoration: underline;">This one fails</span></p><p>And here are the logs from JBoss:</p><p>21:34:04,762 INFO&#160; <a class="jive-link-external-small" href="org.jboss.deployment.dependency.ContainerDependencyMetaData">org.jboss.deployment.dependency.ContainerDependencyMetaData</a> addJndiDependency, JndiDependencyMetaData@ae8e56{01-services/VersionManagerBean/local}</p><p>21:34:04,762 WARN&#160; <a class="jive-link-external-small" href="org.jboss.deployment.MappedReferenceMetaDataResolverDeployer">org.jboss.deployment.MappedReferenceMetaDataResolverDeployer</a> Unresolved references exist in JBossMetaData:[startup-1.19.0-SNAPSHOT.jar#StartupBean:AnnotatedEJBReferenceMetaData{name=ejb/VersionManager,ejb-ref-type=null,link=null,ignore-dependecy=false,mapped/jndi-name=null,resolved-jndi-name=null,beanInterface=interface com.example.services.version.VersionManager}]</p><p>21:34:04,763 INFO&#160; <a class="jive-link-external-small" href="org.jboss.ejb3.deployers.Ejb3DependenciesDeployer">org.jboss.ejb3.deployers.Ejb3DependenciesDeployer</a> Encountered deployment AbstractVFSDeploymentContext@10013305<span></span></p><p>21:34:04,763 INFO&#160; <a class="jive-link-external-small" href="org.jboss.ejb3.deployers.Ejb3DependenciesDeployer">org.jboss.ejb3.deployers.Ejb3DependenciesDeployer</a> Encountered deployment AbstractVFSDeploymentContext@10013305<span></span></p><p>21:34:04,767 ERROR <a class="jive-link-external-small" href="org.jboss.kernel.plugins.dependency.AbstractKernelController">org.jboss.kernel.plugins.dependency.AbstractKernelController</a> Error installing to Real: name=vfs:///opt/src/jboss-6.0.0.Final/server/default/deploy/99-example-startup.ear state=PreReal mode=Manual requiredState=Real: org.jboss.deployers.spi.DeploymentException: Error during deploy: org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData.StartupBean</p><p>&#160;&#160;&#160; at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49) <a class="jive-link-external-small" href="">:2.2.0.GA</a></p><p>&#160;&#160;&#160; at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:185) <a class="jive-link-external-small" href="">:2.2.0.GA</a></p><p>...</p><p>Caused by: java.lang.RuntimeException: Could not resolve @EJB reference: <a class="jive-link-external-small" href="">EJB Reference: beanInterface 'com.example.services.version.VersionManager', beanName 'null', mappedName 'null', lookupName 'null', owning unit 'ComponentDeploymentContext@7745010{org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData.StartupBean}'</a> for environment entry: env/ejb/VersionManager in unit ComponentDeploymentContext@7745010{org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData.StartupBean}</p><p>&#160;&#160;&#160; at org.jboss.ejb3.jndi.deployers.resource.provider.AnnotatedEJBRefResourceProvider.provide(AnnotatedEJBRefResourceProvider.java:99) <a class="" href="http://community.jboss.org/message/586995#586995">Using ejb-jar.xml for @Singleton bean</a></p><p>&#160;&#160;&#160; at org.jboss.ejb3.jndi.deployers.resource.provider.AnnotatedEJBRefResourceProvider.provide(AnnotatedEJBRefResourceProvider.java:50) <a class="" href="http://community.jboss.org/message/586995#586995">Using ejb-jar.xml for @Singleton bean</a></p><p>&#160;&#160;&#160; at org.jboss.switchboard.mc.JndiEnvironmentProcessor.process(JndiEnvironmentProcessor.java:68) <a class="" href="http://community.jboss.org/message/586995#586995">Using ejb-jar.xml for @Singleton bean</a></p><p>&#160;&#160;&#160; at org.jboss.switchboard.mc.deployer.AbstractSwitchBoardDeployer.process(AbstractSwitchBoardDeployer.java:119) <a class="" href="http://community.jboss.org/message/586995#586995">Using ejb-jar.xml for @Singleton bean</a></p><p>&#160;&#160;&#160; at org.jboss.switchboard.mc.deployer.EJBEnvironmentSwitchBoardDeployer.internalDeploy(EJBEnvironmentSwitchBoardDeployer.java:87) <a class="" href="http://community.jboss.org/message/586995#586995">Using ejb-jar.xml for @Singleton bean</a></p><p>&#160;&#160;&#160; at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55) <a class="jive-link-external-small" href="">:2.2.0.GA</a></p><p>&#160;&#160;&#160; at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179) <a class="jive-link-external-small" href="">:2.2.0.GA</a></p><p>&#160;&#160;&#160; ... 39 more</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So I'm probably doing something wrong here, but really I don't see what it is.</p><p>Do I need to provide more information in the ejb-jar.xml?&#160; Is it ok to reference a @Singleton bean from the ejb-jar.xml?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I'm really lost here, so any help will be greatly appreciated.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Cheers,</p><p>/Benoit</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/586995#586995">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>