On Jun 11, 2009, at 8:38 AM, burroinquieto wrote:
I wasn't able to get this working with the 3.1.1 release.
I configured a simple test case as follows:
@LocalClient
public class StockEJBLocalTest extends TestCase {
private Context context;
@EJB
private StockEJBLocal stockEJBLocal;
public void setUp() throws Exception {
initContext();
}
private void initContext() {
Properties contextProps = new Properties();
ResourceBundle rb = ResourceBundle.getBundle("datasource");
Enumeration props = rb.getKeys();
String dsName = null;
while (props.hasMoreElements()) {
String prop = (String)props.nextElement();
if (dsName == null) {
dsName = StringUtils.substringBefore(prop, ".");
}
contextProps.put(prop, rb.getString(prop));
}
contextProps.put(dsName, "new://Resource?type=DataSource");
contextProps.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
try {
context = new InitialContext(contextProps);
context.bind("inject", this);
} catch (Throwable th) {
throw new RuntimeException(th);
}
}
...
}
Resulting output and stack trace:
INFO - Jndi(name=StockEJBLocal) --> Ejb(deployment-id=StockEJB)
INFO - Created Ejb(deployment-id=StockEJB, ejb-name=StockEJB,
container=Default Stateless Container)
INFO - Deployed Application(path=classpath.ear)
java.lang.RuntimeException: javax.naming.NamingException: Unable to
find
injection meta-data for org.dpage.stocksloth.ejb.StockEJBLocalTest.
Ensure
that class was annotated with @org.apache.openejb.api.LocalClient
and was
successfully discovered and deployed. See
http://openejb.apache.org/3.0/local-client-injection.html
at
org
.dpage
.stocksloth.ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
63)
at
org
.dpage.stocksloth.ejb.StockEJBLocalTest.setUp(StockEJBLocalTest.java:
34)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
40)
Caused by: javax.naming.NamingException: Unable to find injection
meta-data
for org.dpage.stocksloth.ejb.StockEJBLocalTest. Ensure that class was
annotated with @org.apache.openejb.api.LocalClient and was
successfully
discovered and deployed. See
http://openejb.apache.org/3.0/local-client-injection.html
at
org
.apache
.openejb.client.LocalInitialContext.inject(LocalInitialContext.java:
251)
at
org
.apache
.openejb.client.LocalInitialContext.bind(LocalInitialContext.java:225)
at javax.naming.InitialContext.bind(InitialContext.java:359)
at
org
.dpage
.stocksloth.ejb.StockEJBLocalTest.initContext(StockEJBLocalTest.java:
60)
... 14 more
Adding the empty META-INF/ejb-jar.xml and META-INF/application-
client.xml
files didn't seem to make any difference. Any ideas?
Your usage looks good. I did encounter something like this in Eclipse
a few days post-release. It seems that in Eclipse we sometimes get
two copies of the @LocalClient annotation loaded and as a result
nothing gets discovered as we're looking for usage of the LocalClient
from classloader one and the application is using LocalClient from
classloader two. A workaround for this is to boot OpenEJB with the
flag 'openejb.tempclassloader.skip=annotations'
On a related note I just noticed the link in the error message still
didn't exist! Ooops! I went ahead and drafted up that page and
included the above information.
http://cwiki.apache.org/OPENEJBx30/local-client-injection.html
It should sync to the openejb.apache.org/ section in an hour.
Definitely let us know if this does or does not work. We definitely
want to make sure this feature operates fine in all environments and
is properly documented.
Thanks for reporting this!
-David