javajsf-2cdiejb-3.1jboss-weld

what is the purpose of including empty beans.xml in CDI implemenations projects?


I am using weld,a RI of CDI as dependency injection component in my JSF-EJB-JPA web app. I see in my project we have empty beans.xml in META-INF/beans.xml in ejb.jar and WEB-INF/beans.xml in my WAR. I don't get it why we need to keep empty beans.xml when there nothing defined in that file?


Solution

  • CDI needs to scan all the classes of a bean archive at start-up and fire a bunch of events because almost any class is automatically a managed bean (read more here), even if it doesn't have any annotations.

    This would incur quite a bit of overhead, especially for jar files that are not meant to have any beans. It is therefore beneficial to explicitly indicate which bean archives should be scanned by including the beans.xml, even an empty beans.xml.