-
1. Re: SFSB injection
iapazmino Sep 29, 2011 12:16 PM (in response to iapazmino)Injecting the reference with @Inject isn't a solution either, because injected reference is null. I supposed because a beans.xml was missing so I added it to the deployment
jar.addAsManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
but it just leads to the previous error, the SFSB is not found so a naming exception is thrown
Caused by: java.lang.RuntimeException: Error retreiving EJB from JNDI StatefulBean (SFSB); BeanClass: class package.ejb.StatefulBean; Local Business Interfaces: [Business interface: class package.ejb.StatefulBean] at org.jboss.weld.integration.ejb.JBossEjbServices.resolveEjb(JBossEjbServices.java:69) at org.jboss.weld.bean.SessionBean.createReference(SessionBean.java:476) at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.<init>(EnterpriseBeanProxyMethodHandler.java:75) at org.jboss.weld.bean.SessionBean.create(SessionBean.java:331) ... 90 more Caused by: javax.naming.NamingException: Could not dereference object at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1508) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:824) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688) at javax.naming.InitialContext.lookup(InitialContext.java:392) at org.jboss.weld.integration.ejb.JBossSessionObjectReference.<init>(JBossSessionObjectReference.java:44) at org.jboss.weld.integration.ejb.JBossEjbServices.resolveEjb(JBossEjbServices.java:65) ... 93 more
How should I inject a @LocalBean @Stateful bean in my test class?
-
2. Re: SFSB injection
aslak Sep 29, 2011 2:00 PM (in response to iapazmino)have you tried @EJB.mappedName ?
-
3. Re: SFSB injection
nwhite Sep 29, 2011 3:46 PM (in response to aslak)I was just about to post about a similar problem and have been down a similar route. I have SLSB which I am trying to inject into the Arquillian test class. I am using the GF 3.1 embedded container and these are No Interface local 3.1 EJBs.
I am shrink wrapping my EJBs into a jar, foo.jar, and I added a persistence.xml manifest resource. The test class injects them like so:
@EJB
FooBean fooBean;
The no-interface SSB simply looks like so:
@Stateless
public class FooBean {
...
}
The first time I got the same EJBInjectionEnricher lookup failure where it tries the default static JDNI names. I went looking at the EJBInjectionEnricher code and noticed that it also will check the mappedName annotation and use this to override the default lookups. I tried various permutations of the mappedName, eg:
mappedName = "java:global/FooBean"
mappedName = "java:global/foo/FooBean"
No joy. Based on the EJB FAQ [1]:
If FooBean is packaged in fooejb.jar and deployed as a stand-alone module, its resulting JNDI name entry is :
java:global/fooejb/FooBean
[1] - http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#SessionBeanGlobalJNDINameAssignment
-
4. Re: SFSB injection
nwhite Sep 29, 2011 4:23 PM (in response to nwhite)Right after I posted this I realized I could see the JNDI names for these beans at deploy time being emitted by the embedded container (buried in all the other noise).
It reports:
INFO: Portable JNDI names for EJB FooBean : [java:global/test/FooBean, java:global/test/FooBean!com.acme.controller.FooBean]
Where is test coming from? Is this something the Arquillian deployment infrastructure is setting up for a default module name? The FAQ seems to indicate this is supposed to be based on:
<module-name> defaults to the unqualified name of the ejb-jar file or .war file in which the EJB component is defined, minus the file extension.
Based on my ShrinkWrap JavaArchive foo.jar I would expect my module name to have been foo.
-Noah