2015-10-05 75 views
7

我有一个关于bean.xml文件的正确格式和用法的问题。在我的项目中,我通常用这个内容我bean.xml文件(不使用explizit bean声明):CDI - 什么是正确的bean.xml格式?

<?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, simple example in CDI fails with WELD-001408 Unsatisfied dependencies我写了一个替代格式:

<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似乎关心这一点。

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

回答

12

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

但是,当你想添加一些内容,请注意,大部分的XML部署描述符命名空间都用Java EE 7进行了更新。这post describes的细节。另外bean-discovery-mode已被添加。

BTW:样品beans.xml我现在使用它看起来像:

<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规范的维护版本)。

相关问题