Using ejb-jar.xml for @Singleton bean
benoit.heinrich Feb 11, 2011 3:59 PMHi everyone,
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.
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.
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 (https://issues.jboss.org/browse/EJBTHREE-2227) I've moved my Singleton to a separate ear file and then I've set my ears to deploy the one after the other.
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.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-app PUBLIC
"-//JBoss//DTD Java EE Application 5.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd">
<jboss-app>
<loader-repository>
com.example:loader=01-services
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
</loader-repository>
</jboss-app>
To reproduce the problem I've created a small example:
Scenario 1, no ejb-jar.xml
Here I'm not using ejb-jar.xml and I'm setting the lookup name inside the @EJB annotation
package com.example.services.startup;
import com.example.services.version.VersionManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;
@Singleton
@Startup
public class StartupBean {
private static final Log log = LogFactory.getLog(StartupBean.class);
@EJB(lookup = "01-services/VersionManagerBean/local")
private VersionManager versionManager;
@PostConstruct
public void startup() {
log.info("System started (version " + versionManager.getVersion() + ")");
}
}
When I deploy this to jboss 6 it sucessfully logs the message and so:
This one works
Scenario 2, jndi mapping done through ejb-jar.xml
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
package com.example.services.startup;
import com.example.services.version.VersionManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;
@Singleton
@Startup
public class StartupBean {
private static final Log log = LogFactory.getLog(StartupBean.class);
@EJB(name = "ejb/VersionManager")
private VersionManager versionManager;
@PostConstruct
public void startup() {
log.info("System started (version " + versionManager.getVersion() + ")");
}
}
And here is the ejb-jar.xml:
ejb-jar.xml
<ejb-jar version="3.1">
<enterprise-beans>
<session>
<ejb-name>StartupBean</ejb-name>
<ejb-class>com.example.services.startup.StartupBean</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ejb/VersionManager</ejb-ref-name>
<local>com.example.services.version.VersionManager</local>
<lookup-name>01-services/VersionManagerBean/local</lookup-name>
</ejb-local-ref>
</session>
</enterprise-beans>
</ejb-jar>
end
The ejb-jar.xml is supposed to show just above... but for some reasons it doesn't show... but when I edit I can see the content of it.
Any idea how I can show the ejb-jar.xml
The ejb-jar.xml is then attached to the post
This one fails
And here are the logs from JBoss:
21:34:04,762 INFO [org.jboss.deployment.dependency.ContainerDependencyMetaData] addJndiDependency, JndiDependencyMetaData@ae8e56{01-services/VersionManagerBean/local}
21:34:04,762 WARN [org.jboss.deployment.MappedReferenceMetaDataResolverDeployer] 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}]
21:34:04,763 INFO [org.jboss.ejb3.deployers.Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@10013305{vfs:///opt/src/jboss-6.0.0.Final/server/default/deploy/99-example-startup.ear/startup-1.19.0-SNAPSHOT.jar/}
21:34:04,763 INFO [org.jboss.ejb3.deployers.Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@10013305{vfs:///opt/src/jboss-6.0.0.Final/server/default/deploy/99-example-startup.ear/startup-1.19.0-SNAPSHOT.jar/}
21:34:04,767 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] 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
at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49) [:2.2.0.GA]
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:185) [:2.2.0.GA]
...
Caused by: java.lang.RuntimeException: Could not resolve @EJB reference: [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}'] for environment entry: env/ejb/VersionManager in unit ComponentDeploymentContext@7745010{org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData.StartupBean}
at org.jboss.ejb3.jndi.deployers.resource.provider.AnnotatedEJBRefResourceProvider.provide(AnnotatedEJBRefResourceProvider.java:99) [:0.1.7]
at org.jboss.ejb3.jndi.deployers.resource.provider.AnnotatedEJBRefResourceProvider.provide(AnnotatedEJBRefResourceProvider.java:50) [:0.1.7]
at org.jboss.switchboard.mc.JndiEnvironmentProcessor.process(JndiEnvironmentProcessor.java:68) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.deployer.AbstractSwitchBoardDeployer.process(AbstractSwitchBoardDeployer.java:119) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.deployer.EJBEnvironmentSwitchBoardDeployer.internalDeploy(EJBEnvironmentSwitchBoardDeployer.java:87) [:1.0.0-alpha-15]
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55) [:2.2.0.GA]
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179) [:2.2.0.GA]
... 39 more
So I'm probably doing something wrong here, but really I don't see what it is.
Do I need to provide more information in the ejb-jar.xml? Is it ok to reference a @Singleton bean from the ejb-jar.xml?
I'm really lost here, so any help will be greatly appreciated.
Cheers,
/Benoit
-
ejb-jar.xml 732 bytes