Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should beans.xml be placed?

I've just upgraded to NetBeans 7.1 from 7.0. On opening a JSF managed bean it "helpfully" told me that it couldn't find my beans.xml file so would I like it created for me. I knew I had a beans.xml file under WEB-INF but I said yes anyway to see what happened. A new beans.xml was created under META-INF for me.

Thinking I'd made a mistake I deleted the file under WEB-INF only to have my application fail at start up. Putting beans.xml back into WEB-INF fixed that problem. This page seems to think both locations are valid: http://seamframework.org/Documentation/WhatIsBeansxmlAndWhyDoINeedIt

So, the question is which folder should beans.xml live in WEB-INF or META-INF?

I'm running GlassFish 3.1.1 and Java 7

like image 609
wobblycogs Avatar asked Jan 24 '12 17:01

wobblycogs


People also ask

Where do I put beans xml?

For a web application, the beans. xml file must be in the WEB-INF directory. For EJB modules or JAR files, the beans. xml file must be in the META-INF directory.

What is Beans xml for?

The beans. xml file is the bean archive descriptor for CDI applications. It can be used for any CDI compliant container, such as Weld which is included in WildFly application server.

Do I need beans xml?

For version 1.0 of CDI , beans. xml is mandatory to enable CDI bean discovery. Without beans. xml , CDI is simply not active in the corresponding archive.

What is xml file in spring boot?

Before Spring 3.0, XML was the only way to define and configure beans. Spring 3.0 introduced JavaConfig, allowing us to configure beans using Java classes. However, XML configuration files are still used today. In this tutorial, we'll discuss how to integrate XML configurations into Spring Boot.


1 Answers

Having beans.xml placed to the WEB-INF directory is fine in your case, because most likely beans are under WEB-INF classes.

Correct place for beans.xml depends about type of archive and location of bean classes.

In specification this is explained as follows:

Bean classes of enabled beans must be deployed in bean archives.

  • A library jar, EJB jar, application client jar or rar archive is a bean archive if it has a file named beans.xml in the META-INF directory.
  • The WEB-INF/classes directory of a war is a bean archive if there is a file named beans.xml in the WEB-INF directory of the war.
  • A directory in the JVM classpath is a bean archive if it has a file named beans.xml in the META-INF directory.
like image 149
Mikko Maunu Avatar answered Sep 20 '22 22:09

Mikko Maunu