0

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>
pbuchheit
  • 1,371
  • 1
  • 20
  • 47

1 Answers1

0

A few things you can try:

Laird Nelson
  • 15,321
  • 19
  • 73
  • 127
  • According to the 1.2 spec (https://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#bean_defining_annotations) @Interceptor IS a bean defining annotation unless I am mistaken somehow. Also the problem persists even if I update the schema to beans_2_0 (which matches the cdi version for the project). – pbuchheit Jan 13 '21 at 13:33
  • Yes, you're quite right. I'll edit my answer to remove the first bullet point. – Laird Nelson Jan 13 '21 at 17:17