Create an interceptor qualifier that ignores the annotation value ()

Is there a way to create an interceptor classifier annotation that ignores the value of the annotation string for qualification?

eg:

Log.java

@Inherited
@InterceptorBinding
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Log {
    String value() default ""; // <---- ignore this
}

LogInterceptor.java

@Log
@Interceptor
public class LogInterceptor implements Serializable {

    ...
}

Usage.java

@Log("message for this log")
public String interceptedMethod(String param) {
    ...
}

This does not work, because the annotation value("message for this log")works as a qualifier, but I want to use value()not a qualifier, but a message log.

+5
source share
1 answer

You can use the @Nonbinding annotation for this purpose. You can force the container to ignore an element of the classifier type by annotating the @Nonbinding element. Take a look at the following example:

@Qualifier
@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
public @interface PayBy {
   PaymentMethod value();
   @Nonbinding String comment() default "";
}

beans @PayBy. CDI, , .

+9

All Articles