Consider the following example :
@MyInterceptorBinding
@ApplicationScoped
public class Example{
@PostConstruct
public void initialize(){
}
}
@InterceptorBinding
@Target(
{TYPE, METHOD}
)
@Retention(RUNTIME)
@Documented
@Inherited
public @interface MyInterceptorBinding{
}
@MyInterceptorBinding
@Interceptor
public class MyInterceptor {
@AroundInvoke
public Object aroundInvoke(InvocationContext ctx) throws Exception
{
ctx.proceed();
}
}
beans.xml :
<?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">
<interceptors>
<class>com.XXX.MyInterceptor</class>
</interceptors>
</beans>
When injecting Example, the initialize() method is called immediately without proceeding first into the aroundInvoke() method defined in the interceptor.
Given the CDI specifications :
http://download.oracle.com/otn-pub/jcp/web_beans-1.0-fr-oth-JSpec/web_beans-1_0-fr-spec.pdf
In Chapter 9. Interceptor Bindings, I have found no indication that any given interceptor should not be applied on a @PostConstruct method.
In Chapter 5. Dependency injection, lookup and EL, under the 5.5.2. Injection of fields and initializer methods, I also have not found any indication that interceptor should not be applied on a @PostConstruct method.
"Any @PostConstruct callback declared by a class X in the type hierarchy of the bean is called after all initializer methods declared by X or by superclasses of X have been called, after all injected fields declared by X or by superclasses of
X have been initialized, and after all Java EE component environment resource dependencies declared by X or by superclasses of X have been injected."
If everything should be initialized/injected shouldn't the defined interceptor be then applied ?
If I am misunderstanding the specification, or if this is not a bug, could the documentation be clarified on that specific case ?
|