告诉 OpenEJB 忽略 MDB
我为一个活动编写了一个单元测试,该活动最终将消息放入队列中。一旦消息被放入该队列,消息驱动的 Bean 就会开始处理。但我不想在单元测试中测试 MDB。我如何告诉 OpenEJB 忽略它们?
我设置了 OpenEJB 的几个属性:
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
p.setProperty("openejb.deployments.classpath.include", ".*");
p.setProperty("openejb.localcopy", "false");
// Messaging
p.put("MyJmsResourceAdapter",
"new://Resource?type=ActiveMQResourceAdapter");
// Do not start the ActiveMQ broker
p.put("MyJmsResourceAdapter.BrokerXmlConfig", "");
p.put("MyJmsConnectionFactory",
"new://Resource?type=javax.jms.ConnectionFactory");
p.put("MyJmsConnectionFactory.ResourceAdapter", "MyJmsResourceAdapter");
p.put("queue/MyQueue",
"new://Resource?type=javax.jms.Queue");
我知道我必须设置 openejb.deployments.classpath.exclude,但我无法找出正确的值:
p.setProperty("openejb.deployments.classpath.exclude", "org.example.mdb.*");
例如我的类名为 org.示例.mdb.MyMDB。
I wrote an unit-test for an activity which finally puts a message into a queue. As soon as a message is put into that queue, a message driven bean starts processing. But I don't want to test MDBs in a unit test. How can I tell OpenEJB to ignore them?
I set up OpenEJB with several properties:
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
p.setProperty("openejb.deployments.classpath.include", ".*");
p.setProperty("openejb.localcopy", "false");
// Messaging
p.put("MyJmsResourceAdapter",
"new://Resource?type=ActiveMQResourceAdapter");
// Do not start the ActiveMQ broker
p.put("MyJmsResourceAdapter.BrokerXmlConfig", "");
p.put("MyJmsConnectionFactory",
"new://Resource?type=javax.jms.ConnectionFactory");
p.put("MyJmsConnectionFactory.ResourceAdapter", "MyJmsResourceAdapter");
p.put("queue/MyQueue",
"new://Resource?type=javax.jms.Queue");
I know I must set openejb.deployments.classpath.exclude
, but I can't figure out the right value:
p.setProperty("openejb.deployments.classpath.exclude", "org.example.mdb.*");
For example my class is named org.example.mdb.MyMDB
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是我的 2 美分:
<块引用>
请注意,默认情况下这些设置将
只影响 OpenEJB 将使用的 jar
没有时扫描带注释的组件
找到描述符。如果你愿意
使用这些设置来过滤
输出包含描述符的罐子,
设置
openejb.deployments.classpath.filter.descriptors
属性为true。默认为 false
just my 2 cents:
".*org/example/mdb.*" or ".*org.example.mdb.*"
我们没有这个功能,但如果您想做一些黑客活动,可以轻松添加它 - 总是欢迎新的贡献和贡献者。
这个类将完全执行您想要的操作...以及一些您可能不想要的操作:) 它会删除所有 MDB 和 JMS 资源引用(好的部分)它会删除所有实体 bean 和持久性单元引用(您可能不想要的部分)。我们编写它是因为加载 ActiveMQ 或 OpenJPA 时遇到一些调试问题。如果您清理了它,我们很乐意将其收回并作为一项功能予以支持。
有一个类似的功能 删除所有 Web 服务。它安装在 ConfigurationFactory 如果设置了特定的系统属性。应该很容易在
ConfigurationFactory
中的同一位置使用类似的标志轻松插入“MDB & JMS”删除器事实上,因为在 OpenEJB 中,所有注释和 xml 元数据都合并到一个对象树中(这也是一个 JAXB 树),您可以在实际部署应用程序之前对其进行非常强大的转换。例如,将特定的 bean 替换为模拟版本。
我认为其中一件事情会成为一项出色的功能,但还没有时间去做。也就是说,在我们将树送去部署之前,制作一些干净的钩子,以便人们可以弄乱这棵树。欢迎任何阅读本文的人加入并尝试一下(开源!)。
We don't have that feature, but it could easily be added if you wanted to do a little hacking -- new contributions and contributors are always welcome.
This class will do exactly what you want... and a few things you probably don't want :) It strips out all MDBs and JMS resource references (the good part) and it strips out all entity beans and persistence unit references (the part you probably don't want). We wrote it due to some debugging issues we were having when either ActiveMQ or OpenJPA were loaded. If you cleaned it up we'd happily take it back and support it as a feature.
There is a similar feature which strips out all web services. It is installed in the ConfigurationFactory if a specific system property is set. Should be easy to plug an "MDB & JMS" remover using a similar flag at basically that same place in
ConfigurationFactory
In fact since in OpenEJB all annotation and xml meta-data is merged into one object tree (which is also a JAXB tree), you could do pretty powerful transformations of the app prior to it being actually deployed. Say for example swap out specific beans for mock versions.
One of those things I think would make an excellent feature but haven't yet had the time to work on. I.e. making some clean hook for people to mess with the tree just before we send it off for deployment. Anyone reading this is welcome to jump in and take a stab at it (yay open source!).