cdi - cannot inject (@EJB) ejb using its superclass -
i learning both cdi , ejb. looking @ weld's explanation of cdi (http://docs.jboss.org/weld/reference/latest/en-us/html/beanscdi.html), states
the unrestricted set of bean types session bean contains local interfaces of bean , superinterfaces. if session bean has bean class local view, unrestricted set of bean types contains bean class , superclasses. in addition, java.lang.object bean type of every session bean. remote interfaces not included in set of bean types.
i trying test particular part
the unrestricted set of bean types contains bean class , superclasses
so have created 2 ejbs: referencedejb extends dummyparent , mainejb has reference ejb
dummyparent.java
package com.etm.ejbtest; public abstract class dummyparent { public dummyparent() { } public void sayhi() { system.out.println("hi!"); } }
referencedejb.java
package com.etm.ejbtest; import javax.annotation.postconstruct; import javax.ejb.singleton; import javax.ejb.startup; @singleton @startup public class referencedejb extends dummyparent { public referencedejb() { } @postconstruct protected void init() { system.out.println("init of referencedejb"); } }
mainejb.java
package com.etm.ejbtest; import javax.annotation.postconstruct; import javax.ejb.ejb; import javax.ejb.singleton; import javax.ejb.startup; @singleton @startup public class mainejb { @ejb private dummyparent dummyparent; public mainejb() { } @postconstruct protected void init() { system.out.println("init of mainejb"); dummyparent.sayhi(); } }
i running on jboss 7 error saying
no ejb found interface of type 'com.etm.ejbtest.dummyparent' binding com.etm.ejbtest.mainejb/dummyparent
any idea why not work?
don't confuse cdi , @ejb
annotation; @ejb
injection managed ejb container, not cdi; inject ejb, , dummyparent
not ejb.
this sounds counter-intuitive new on scene. ejbs came along before official java ee support cdi.
a google search injecting ejbs via cdi may shed light on you.
Comments
Post a Comment