简体   繁体   English

OpenEJB-排除单个bean

[英]OpenEJB - exclude single beans

I'm testing my application using junit and OpenEJB container to provide context for my beans. 我正在使用junit和OpenEJB容器为我的bean提供上下文来测试我的应用程序。 It's finding all beans from classpath and starting them. 它从类路径中找到所有bean并启动它们。 Unfortunatelly there are some beans I would like to remove from context, so I can replace those beans with other implementations, mocking certain functionalities. 不幸的是,有一些我想从上下文中删除的bean,所以我可以用其他实现替换那些bean,模拟某些功能。

I'm aware of openejb.deployments.classpath.exclude property. 我知道openejb.deployments.classpath.exclude属性。 I even tried to use it as follows properties.put("openejb.deployments.classpath.exclude", ".*/CommonCache.*"); 我什至尝试按以下方式使用它properties.put("openejb.deployments.classpath.exclude", ".*/CommonCache.*"); as it was sugested in this SO question . 正如在这个SO问题中被轻描淡写的那样。

OpenEJB sees this property but bean is still starting as shown in logs below. OpenEJB看到此属性,但是bean仍在启动,如下面的日志所示。

Using 'openejb.deployments.classpath.exclude=.*/CommonCacheBean.*'
Auto-deploying ejb CommonCacheBean: EjbDeployment(deployment-id=CommonCacheBean)
Jndi(name="java:global/ejbs/CommonCacheBean!my.package.ICommonCache")
Created Ejb(deployment-id=CommonCacheBean, ejb-name=CommonCacheBean, container=Default Stateless Container)

So there is my question. 所以这是我的问题。 Is there a way to exclude single bean(s) from OpenEJB context? 有没有办法从OpenEJB上下文中排除单个bean? It doesn't matter to me if it will be achieved this config way or by manual operations in java code. 对我而言,是否可以通过这种配置方式或通过Java代码中的手动操作来实现都无所谓。

If anyone is interested i didn't manage to remove beans from context. 如果有人感兴趣,我不会从上下文中删除bean。 Although there is an unbind() method in context it does not seem to work on OpenEJB context. 尽管上下文中有一个unbind()方法,但它似乎不适用于OpenEJB上下文。 I succeded in replacing beans manually with rebind() but it was too late because they were already injected into another beans. 我成功地用rebind()手动替换了bean,但是为时已晚,因为它们已经被注入到另一个bean中了。

They way i solved my problem was by using annotaion @Alternative on mock implementation. 他们解决我的问题的方法是在模拟实现中使用注释@Alternative I also had to add entries in beans.xml to show container those beans and change the way I inject them from @EJB to @Inject . 我还必须在beans.xml添加条目以向容器显示那些bean,并将将它们从@EJB注入的方式更改为@Inject

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM