Details
-
Bug
-
Resolution: Won't Do
-
Major
-
None
-
EJB 3.0 RC9 - Patch 1
-
None
-
None
Description
I have 2 stateless session EJBs, RecipientServiceBean and InjectedServiceBean.
RecipientService exposes a remote interface. InjectedService exposes only a local interface and is injected into the 'injectedService' field of the RecipientServiceBean
--------------------------------------------------- RecipientServiceBean ---------------------------------------------------
@Stateless(name="RecipientServiceBean")
@Remote(RecipientService.class)
public class RecipientServiceBean implements RecipientService {
@EJB(mappedName="overrideinjection/InjectedServiceBean/local")
private InjectedService injectedService;
public String saySomething()
{ return "Hello: " + injectedService.getResponse(); }}
--------------------------------------------------- InjectedServiceBean ---------------------------------------------------
@Stateless(name="InjectedServiceBean")
@Local(InjectedService.class)
public class InjectedServiceBean implements InjectedService {
public String getResponse()
{ return "This is the real service"; }}
---------------------------------------------------------------------------------------------------------------------------------------------------------
I now want to override the injection specified by the @EJB annotation to inject a stub service. The stub service and ejb-jar.xml included is as follows
--------------------------------------------------- RecipientServiceStubBean ---------------------------------------------------
public class InjectedServiceStubBean implements InjectedService {
public String getResponse()
{ return "THIS IS THE STUB"; }}
--------------------------------------------------- ejb-jar.xml ---------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
version="3.0">
<enterprise-beans>
<session>
<ejb-name>RecipientServiceBean</ejb-name>
<remote>com.sadalbari.test.overrideinjection.RecipientService</remote>
<ejb-class>com.sadalbari.test.overrideinjection.impl.RecipientServiceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-local-ref>
<ejb-ref-name>ejb/InjectedService</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>com.sadalbari.test.overrideinjection.InjectedService</local>
<ejb-link>InjectedServiceStubBean</ejb-link>
<injection-target>
<injection-target-class>com.sadalbari.test.overrideinjection.impl.RecipientServiceBean</injection-target-class>
<injection-target-name>injectedService</injection-target-name>
</injection-target>
</ejb-local-ref>
</session>
<session>
<ejb-name>InjectedServiceStubBean</ejb-name>
<local>com.sadalbari.test.overrideinjection.InjectedService</local>
<ejb-class>com.sadalbari.test.overrideinjection.impl.InjectedServiceStubBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
---------------------------------------------------------------------------------------------------------------------------------------------------------
A dump of my JNDI view at this point
+- overrideinjection (class: org.jnp.interfaces.NamingContext)
+- RecipientServiceBean (class: org.jnp.interfaces.NamingContext) | |
+- remote (proxy: $Proxy61 implements interface com.sadalbari.test.overrideinjection.RecipientService,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject) | |
+- InjectedServiceStubBean (class: org.jnp.interfaces.NamingContext) | |
+- local (proxy: $Proxy56 implements interface com.sadalbari.test.overrideinjection.InjectedService,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject) | |
+- InjectedServiceBean (class: org.jnp.interfaces.NamingContext) | |
+- local (proxy: $Proxy56 implements interface com.sadalbari.test.overrideinjection.InjectedService,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject) |
---------------------------------------------------------------------------------------------------------------------------------------------------------
The result is that the injection is not overridden and the stub is not used in preference to the 'real service':
Hello: This is the real service
I can work around this issue by removing the @EJB annotation and ALWAYS declaring the injection in the ejb-jar.xml in which case I get:
Hello: THIS IS THE STUB
Thanks
Justin
Attachments
Issue Links
- blocks
-
JBPAPP-1387 EJBTHREE-879 - Injection metadata in ejb-jar.xml does not override @EJB annotation
- Resolved