I'm having a bit of an issue with Weld CDI Interceptors that I just can't seem to resolve. When I include an <interceptors>
tag in the beans.xml of an ejb project, the <class>
tags are flagged as invalid. The message in eclipse reads:
com.tura.person.service.TransactionInterceptor" is not an interceptor class [JSR-365 §9.4]
After doing a bit of research, it seems like the problem may be that I have bean-discovery-mode set to annotated. I want to keep that setting, so how do I make my interceptors visible without changing bean-discovery-mode to 'all' ?
For reference here is the interceptor interface:
package com.tura.person.service;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import javax.interceptor.InterceptorBinding;
@InterceptorBinding
@Target({METHOD, TYPE})
@Retention(RUNTIME)
public @interface Transactional {}
the implementation:
package com.tura.person.service;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
@Transactional
@Interceptor
public class TransactionInterceptor {
@AroundInvoke
public Object manageTransaction(InvocationContext ctx) throws Exception {
return null;
}
}
and the beans.xml:
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated" >
<interceptors>
<class>com.tura.person.service.TransactionInterceptor</class>
</interceptors>
</beans>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…