Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

java - beans.xml Interceptor Invalid with Discovery Mode 'annotated'

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A few things you can try:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...