CDI - 什么是正确的bean.xml格式? [英] CDI - what is the correct bean.xml format?

查看:483
本文介绍了CDI - 什么是正确的bean.xml格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对bean.xml文件的正确格式和用法有疑问。在我的项目中,我通常将此内容用于我的bean.xml文件(不使用explizit bean声明):

I have a question about the correct format and usage of the bean.xml file. In my projects I typically used this content for my bean.xml files (no explizit bean declaration used):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

这在WildFly 8和9中运行良好。但我在GlassFish 4中有部署问题。在问题中: Glassfish 4,CDI中的简单示例失败了WELD-001408不满意的依赖关系我写了另一种格式:

This works well in WildFly 8 and 9. But I have deployment issues in GlassFish 4. In the question: Glassfish 4, simple example in CDI fails with WELD-001408 Unsatisfied dependencies I wrote about an alternative format:

<beans
   xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
                  http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
          bean-discovery-mode="all">
</beans>

使用了不同的命名空间。并且GlassFish4似乎关心这一点。

There a different namespaces used. And GlassFish4 seems to care about that.

用于JEE7的空bean.xml文件的正确格式是什么?

What is the correct format of an empty bean.xml File used for JEE7 ?

推荐答案

正确空 beans.xml 可以是完全空文件,真的; - )

Correct empty beans.xml can be totally empty file, really ;-)

但是当你想添加一些内容时,请注意大多数XML部署描述符命名空间已经在Java EE 7中更新过了。这个描述详细信息。此外还添加了 bean-discovery-mode

But when you want to add some content, please notice that most of the XML deployment descriptor namespaces have been updated in Java EE 7. This post describes the details. Also bean-discovery-mode has been added.

BTW:示例 beans.xml 我现在使用的是:

BTW: Sample beans.xml which I'm using right now looks like:

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       version="1.2" bean-discovery-mode="annotated">

    <!-- some content -->
</beans>

您可能会注意到 version =1.2的使用属性 - 您可以自由地将其设置为 1.1 。它只是提醒读者项目正在使用CDI 1.2(实际上只是 CDI 1.1 规范的维护版本)。

You may notice the usage of version="1.2" attribute - you can freely set it to 1.1. It just serves as a reminder to the reader that project is using CDI 1.2 (which in fact is just a Maintenance release of the CDI 1.1 Specification).

这篇关于CDI - 什么是正确的bean.xml格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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