-
1. Re: Injection question regarding @EJB in a JavaBean
cavani Mar 4, 2008 5:54 PM (in response to jensaug.jens.augustsson.eu)You can use spring-like xml file one-by-one in your WAR
<component name="name" class="SLSB"/>
You can wrap JNDI lookup one-by-one using annotation or one-to-many using EL injection:
@Name("x") @Stateless class XWrapper implements WrapperLocal { @EJB public XLocal x @Unwrap public XLocal getX() { return x } }
then package all wrappers like a second ejb module inside your ear (not war because ejb is not allowed there).
@Name("name") class EJBLookup { Object lookup(String jndi) { // lookup code } } @Name class JavaBean { @In("#{name.lookup('x')") public XLocal x; }
I didn't test, but I used similar approach sometime.
Thanks,
-
2. Re: Injection question regarding @EJB in a JavaBean
cavani Mar 4, 2008 6:04 PM (in response to jensaug.jens.augustsson.eu)...
Between the two last approach, you can use factory:
@Name('factory') class Factory { private Object lookup(String jndi) { ... } @Factory("x") public XLocal getX() { return lookup("x"); } @Factory("y") public YLocal getY() { return lookup("y"); } } @Name("name") class Bean { @In private XLocal x; @In private YLocal y; }
Thanks,
-
3. Re: Injection question regarding @EJB in a JavaBean
jensaug.jens.augustsson.eu Mar 4, 2008 8:14 PM (in response to jensaug.jens.augustsson.eu)Ciro,
Thanks a bunch, three quick beautiful solutions on a problem I've spent far too much time on. Took number one, adding one line per SLSB in my components.xml is totally acceptable.
Added an auto-create too so my client simply can use @In
<component auto-create="true" class="org.domain.dunno.session.ForaBean" name="fora" />
Again, thanks.
Jens
-
4. Re: Injection question regarding @EJB in a JavaBean
jensaug.jens.augustsson.eu Mar 5, 2008 9:15 AM (in response to jensaug.jens.augustsson.eu)Btw, using @In will inject this reference at invocation time - is there any way to inject this reference at component instatiation time instead, using annotations? Like @InAtInstansiationTime?
I know I could do it in component.xml using the 'property' element, but then I'd need to add a 'component' element for every JavaBean needing a EJB reference too.
br,
Jens -
5. Re: Injection question regarding @EJB in a JavaBean
nickarls Mar 5, 2008 9:28 AM (in response to jensaug.jens.augustsson.eu)Well, you could use @Create to do foo = Components.getInstance()...
-
6. Re: Injection question regarding @EJB in a JavaBean
jensaug.jens.augustsson.eu Mar 5, 2008 10:58 AM (in response to jensaug.jens.augustsson.eu)I tried your nice
one-to-many using EL injection
- the no-config concept is of course interesting - but I always get a...javax.faces.el.ReferenceSyntaxException: javax.el.ELException: Error Parsing: #{ejbLookup.lookup('ForaBean')}
...Exception due to the parenthesis - works though if I add a getter method for a lookup property I've hardcoded. Appers that only EL property binding can be done using @In, not EL method binding?
br,
Jens -
7. Re: Injection question regarding @EJB in a JavaBean
jensaug.jens.augustsson.eu Mar 5, 2008 9:35 PM (in response to jensaug.jens.augustsson.eu)True, thanks,
But them I get somewhat too close to what I'm trying to get away from: Having to manually lookup EJB references in the @Create method!