Failed to start local OpenEJB client

Note that I very closely reflect the example given here .

In fact, my situation is somewhat simpler, because I do not even test with a unit of persistence at the moment. My test project provides a simple MDB and bean session; both the MDB and the bean session load as usual and can be successfully tested (limited) without injection.

The proposed injection with the @LocalClient annotation on my unit tests fails with a known error:

javax.naming.NamingException: Unable to find injection meta-data for [your-class]. 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

When I visit this page, he informs me that I may need to add an additional property to the context setting of the test case. So now it looks like this:

 @Override public void setUp() throws Exception { initializeContext(); } 
 public void initializeContext() { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); // the property i've added p.put("openejb.tempclassloader.skip", "annotations"); try { InitialContext initialContext = new InitialContext(p); initialContext.bind("inject", this); } catch (Throwable throwable) { throwable.printStackTrace(); throw new RuntimeException(throwable); } } 

But he still fails. I really like this idiom, and I would be very happy if I could successfully use it in my projects.

A few other notes:

  • I provide the "empty" ejb-jar.xml (in src / main / resources) and the application-client.xml (in src / test / resources) proposed by Apache to tell OpenEJB about scanning the class path [UPDATE: as it turned out, I did it wrong. See My answer below for a suggestion that worked for me.]
  • Test cases annotated with @LocalClient are not identified by the OpenEJB engine, since they are actually received and handled properly (for example, my MDBs)

Thanks in advance for your help or guidance.

+4
source share
2 answers

This problem is probably caused by the incorrect location of the descriptors that tell OpenEJB what types of modules are available.

To make sure the test classes are correctly built, make sure that you put the file named application-client.xml in src/test/resources/META-INF with the following contents:

<application-client/>

This should force OpenEJB to scan and respond to the presence of @LocalClient annotations.

+7
source

I had a similar problem when I tried to test the material in a test project called tomee-embedded-trial , and it turned out that open ignores the material called Me -. *.

I fixed it for me by specifying the following system properties: openejb.deployments.classpath.include=".*-trial.*" openejb.deployments.package.include=".*-trial.*"

0
source

All Articles