What is the correct bean.xml format?

I have a question about the correct format and use of the bean.xml file. In my projects, I usually used this content for my bean.xml files (without using explizit bean):

<?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> 

This works well in WildFly 8 and 9. But I have deployment problems in GlassFish 4. In the question: Glassfish 4, a simple example in CDI does not work with WELD-001408 Unsatisfactory 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> 

Different namespaces are used there. And GlassFish4 seems to care about that.

What is the correct format for the empty bean.xml file used for JEE7?

+7
java cdi glassfish jboss-weld
source share
1 answer

The correct empty beans.xml may be a completely empty file, indeed; -)

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

BTW: The beans.xml example that I'm using now looks like this:

 <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> 

You may notice the use of the version="1.2" attribute - you can freely set it to 1.1 . It just serves as a reminder to the reader that the project uses CDI 1.2 (in fact, this is just a maintenance release of the CDI 1.1 specification ).

+12
source share

All Articles