A CDI bean is an application component that encapsulates some business logic. Beans can be used either by some Java code or by the unified EL (expression language used in JSP and JSF technologies). Beans' life cycles are managed by the container and can be injected into other beans. All you need to do to define a bean is to write a POJO and declare it to be a CDI bean. To declare that, there are two primary approaches:
- Using annotations
- Using the beans.xml file
Both ways should work; however, folks prefer using annotations over XML as it's handy and included in the actual coding context. So, why is XML just over there? Well, that's because annotations are relatively new in Java (released in Java 5). Until they were introduced, there was no other way in Java than XML to provide configuration information to your application...