覆盖 xml 文件中的 CDI 配置

Overwrite CDI configuration in xml file

在 jee(EJB、servlet)和许多其他 java 库 (spring) 中,有一条通用规则,即通过注释完成的所有操作都可以用 xml 覆盖文件。

在我看来,对于 CDI,上述规则不适用。请确认或否定我的意见。

beans.xml是否仅接受:替代装饰器拦截器和扫描顶级元素(netbeans 仅建议这样做)?

例如,我可以仅通过 beans.xml 文件创建 @Named CDI bean 吗?

我可以在 beans.xml 文件中覆盖 @Interceptor 的 @Priority 吗?

好吧,正如我在之前的 , you cannot overwrite interceptors in beans.xml. That's different from Spring where you can overwrite annotations by XML files or even merge them together. beans.xml is meant only for couple of following purposes (you can verify by looking at XSD schema)

中指出的
  • 定义拦截器类
  • 定义装饰器
  • 正在注册备选方案
  • 条件扫描

这就是您目前使用 CDI 1.1 可以做的所有事情 beans.xml