Monday, November 12, 2018

"bean- discovery-mode" attribute for Contexts and Dependency Injection

Java EE 7 platform enables default CDI injection for all beans that explicitly contain a CDI scope annotation and EJBs. A new attribute, “bean- discovery-mode” attribute is added to beans.xml:
<beans xmlns=http://xmlns.jcp.org/xml/ns/javaeexmlns:xsi=http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation=http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsdbean-discovery- mode=all>
</beans>
This attribute can take the following values:
  1. all: All types in the archive are considered for injection. 
  2. annotated: Only types with an explicitly declared CDI scope are considered for injection. 
  3. none: Disable CDI
By default, CDI interceptors are disabled and can be enabled and ordered via the @javax.interceptor.Interceptor.Priority annotation as shown:
@Priority(Interceptor.Priority.APPLICATION+10)
@Interceptor
@Logging
public class LoggingInterceptor {
//. . . }
This can be done for decorators and alternatives too.