OpenEJB本地客户端注入失败 [英] OpenEJB Local Client Injection Fails

查看:327
本文介绍了OpenEJB本地客户端注入失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意,我正在镜像此处给出的示例非常接近。

Note that I'm mirroring the example given here very closely.

事实上,我的情况有点简单,因为我现在甚至没有使用持久性单元进行测试。我的测试项目提供了一个简单的MDB和一个会话bean; MDB和会话bean都正常加载,并且可以在没有注入的情况下成功测试(以约束的方式)。

In fact, my situation is somewhat simpler as I'm not even testing with a persistence unit at this point. My test project provides a simple MDB and a session bean; both the MDB and the session bean are getting loaded as normal, and can be successfully tested (in a constrained fashion) without injection.

使用<$ c建议的注入单元测试中的$ c> @LocalClient 注释失败并出现已知错误:

The suggested injection with the @LocalClient annotation on my unit tests is failing with the known error:

javax.naming.NamingException :无法为[您的班级]找到注入元数据。确保该类已使用@ org.apache.openejb.api.LocalClient进行批注,并已成功发现并部署。请参见 http://openejb.apache.org/3.0/local-client-injection。 html

当我访问此页面时,它通知我可能需要为我的测试用例上下文设置添加额外的属性。所以现在看起来像:

When I visit this page it informs me that I may need to add an extra property to my test case context setup. So that now looks like:


@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 it's still failing. I really like this idiom and would be very excited if I could successfully use it in my projects.

其他一些注释:


  • 我提供了一个'空'ejb-jar.xml(在src / main / resources中)和一个application-client.xml(在src / test / resources中),如下所示Apache告诉OpenEJB扫描类路径[更新:事实证明,我做错了。请参阅下面的答案,了解对我有用的建议。]

  • 使用 @LocalClient 注释的测试用例不会被OpenEJB引擎实际上正在被拾取并正确处理(例如,我的MDB)

  • I am providing an 'empty' ejb-jar.xml (in src/main/resources) and an application-client.xml (in src/test/resources) as suggested by Apache to tell OpenEJB to scan the classpath [UPDATE: as it turns out, I was doing this wrong. See my answer below for the suggestion that worked for me.]
  • The test cases annotated with @LocalClient aren't identified by the OpenEJB engine as actually getting picked up and processed properly (as my MDBs are, for example)

提前感谢任何帮助或指导。

Thanks in advance for any help or guidance.

推荐答案

这个问题很可能是由描述符的位置不正确引起的,这些描述符暗示OpenEJB有哪些模块可用。

This issue is likely caused by improper location of the descriptors which hint OpenEJB which sorts of modules are available.

为确保正确选择测试类,请确保放置名为 application-client.xml的文件 src / test / resources / META-INF ,内容如下:

To ensure the test-classes get picked up properly, make sure you're placing a file named application-client.xml at src/test/resources/META-INF with the following content:


< application-client />

这应该强制OpenEJB扫描并对 @LocalClient 注释的存在做出反应。

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

这篇关于OpenEJB本地客户端注入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆