This content has been marked as final.
Show 1 reply
-
1. Re: Possible to use @EJB or @In for ejb3 packed in another archive?
thokuest Mar 26, 2010 7:16 PM (in response to mike82)I see two options to obtain EJBs from an external archive:
1) Define your EJB components via components.xml
<?xml version="1.0" encoding="UTF-8"?> <components ...> <!-- [...] --> <component name="ctjc" jndi-name="MyBean/local" class="package.MyBeanLocal" ... /> <!-- [...] --> </components>
2) Using @Factory annotation
@Name("ejbFactory") @AutoCreate public class EJBFactory { // ... private @Logger Log log; private Object lookup(String jndiName) { Context ctx = new InitialContext(); try { return ctx.lookup(jndiName); } catch (Exception e) { log.warn("EJB lookup failed", e); return null; } } @Factory(autoCreate=true, ...) public MyBeanLocal getCtjc() { return (MyBeanLocal) lookup("MyBean/local"); } // ... }
You should be able to use your EJB in your components as follows:
public class FancyComponent { // ... private @In MyBeanLocal ctjc; // ... }
I hope that helps!