[英]Specifying a custom path of beans.xml for CDI
When I use Spring and want to write a unit test, I can specify a custom context configuration in various ways, for example, by providing a different path of the context.xml
.当我使用 Spring 并且想要编写单元测试时,我可以通过多种方式指定自定义上下文配置,例如,通过提供
context.xml
的不同路径。
But I don't see the way how to do that for CDI if I want to use a custom dependencies configuration for testing in the same maven module.但是,如果我想使用自定义依赖项配置在同一个 maven 模块中进行测试,我不知道如何为 CDI 执行此操作。
The documentation is very strict about this point:文档对这一点非常严格:
For EJB modules or JAR files, the beans.xml deployment descriptor, if present, must be in the META-INF directory.
对于 EJB 模块或 JAR 文件,beans.xml 部署描述符(如果存在)必须位于 META-INF 目录中。
If there is already /META-INF/beans.xml
in the sources, I can not place a different one into the test-resources (it simply will be ignored).如果源代码中已经存在
/META-INF/beans.xml
,我就不能在测试资源中放置一个不同的(它会被忽略)。
Is any way to configure Weld/CDI
, may be by using some system variables, to change the path of the beans.xml
?有没有办法配置
Weld/CDI
,可能是通过使用一些系统变量来更改beans.xml
的路径?
For EJB modules or JAR files, the beans.xml deployment descriptor, if present, must be in the META-INF directory.
对于 EJB 模块或 JAR 文件,beans.xml 部署描述符(如果存在)必须位于 META-INF 目录中。
That is true, however that concerns an already created/packaged JAR which you then use as a dependency of your app.确实如此,但是这涉及到一个已经创建/打包的 JAR,然后您将其用作应用程序的依赖项。 But your app can have it's own
beans.xml
too.但是您的应用程序也可以拥有自己的
beans.xml
。 beans.xml
is just a means to define one bean archive and certain structures (interceptors, decorators, ...) within that archive. beans.xml
只是定义一个 bean 档案和该档案中的某些结构(拦截器、装饰器等)的一种方法。 That means, for instance, that an interceptor enabled via beans.xml
inside that JAR library will not be enabled in your application unless you specify it in beans.xml
of that app too.这意味着,例如,通过该 JAR 库中的
beans.xml
启用的拦截器将不会在您的应用程序中启用,除非您也在该应用程序的beans.xml
中指定它。 Hence the link you see between the documentation and the testing you are asking about might not be correct/relevant.因此,您在文档和您询问的测试之间看到的链接可能不正确/不相关。 Not sure if I got you right there, though.
不过,不确定我是否让你在那里。
Is any way to configure Weld, may be through using some system variables, to change the path of the beans.xml?
有没有办法配置Weld,可能是通过使用一些系统变量,来改变beans.xml的路径?
No, there isn't.不,没有。 But in EE you mostly test with Arquillian and that allows you (among other things) to define a test deployment.
但是在 EE 中,您主要使用 Arquillian 进行测试,这允许您(除其他外)定义测试部署。 There you can include any custom
beans.xml
you desire.您可以在其中包含您想要的任何自定义
beans.xml
。 That's also what Weld/CDI TCK tests use most of the time.这也是 Weld/CDI TCK 测试大部分时间使用的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.