[jboss-user] [EJB3] - Using ejb-jar.xml for @Singleton bean
Benoit Heinrich
do-not-reply at jboss.com
Fri Feb 11 15:47:20 EST 2011
Benoit Heinrich [http://community.jboss.org/people/benoit.heinrich] created the discussion
"Using ejb-jar.xml for @Singleton bean"
To view the discussion, visit: http://community.jboss.org/message/586995#586995
--------------------------------------------------------------
Hi 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 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 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
<code>
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() + ")");
}
}
</code>
And here is the ejb-jar.xml:
This one fails
And here are the logs from JBoss:
21:34:04,762 INFO org.jboss.deployment.dependency.ContainerDependencyMetaData org.jboss.deployment.dependency.ContainerDependencyMetaData addJndiDependency, JndiDependencyMetaData at ae8e56{01-services/VersionManagerBean/local}
21:34:04,762 WARN org.jboss.deployment.MappedReferenceMetaDataResolverDeployer 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 org.jboss.ejb3.deployers.Ejb3DependenciesDeployer Encountered deployment AbstractVFSDeploymentContext at 10013305
21:34:04,763 INFO org.jboss.ejb3.deployers.Ejb3DependenciesDeployer org.jboss.ejb3.deployers.Ejb3DependenciesDeployer Encountered deployment AbstractVFSDeploymentContext at 10013305
21:34:04,767 ERROR org.jboss.kernel.plugins.dependency.AbstractKernelController 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 at 7745010{org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData.StartupBean}' for environment entry: env/ejb/VersionManager in unit ComponentDeploymentContext at 7745010{org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData.StartupBean}
at org.jboss.ejb3.jndi.deployers.resource.provider.AnnotatedEJBRefResourceProvider.provide(AnnotatedEJBRefResourceProvider.java:99) http://community.jboss.org/message/586995#586995 Using ejb-jar.xml for @Singleton bean
at org.jboss.ejb3.jndi.deployers.resource.provider.AnnotatedEJBRefResourceProvider.provide(AnnotatedEJBRefResourceProvider.java:50) http://community.jboss.org/message/586995#586995 Using ejb-jar.xml for @Singleton bean
at org.jboss.switchboard.mc.JndiEnvironmentProcessor.process(JndiEnvironmentProcessor.java:68) http://community.jboss.org/message/586995#586995 Using ejb-jar.xml for @Singleton bean
at org.jboss.switchboard.mc.deployer.AbstractSwitchBoardDeployer.process(AbstractSwitchBoardDeployer.java:119) http://community.jboss.org/message/586995#586995 Using ejb-jar.xml for @Singleton bean
at org.jboss.switchboard.mc.deployer.EJBEnvironmentSwitchBoardDeployer.internalDeploy(EJBEnvironmentSwitchBoardDeployer.java:87) http://community.jboss.org/message/586995#586995 Using ejb-jar.xml for @Singleton bean
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
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/586995#586995]
Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110211/299218e7/attachment-0001.html
More information about the jboss-user
mailing list