Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create interceptor qualifier thats ignore annotation value()

Is there a way to create a interceptor qualifier annotation that ignores the annotation string value for qualifying?

for example:

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 doesn't work because the annotation value("message for this log") works as qualifier but I want to use the value() not as qualifier, but message log.

like image 671
ethanxyz_0 Avatar asked Apr 16 '13 21:04

ethanxyz_0


1 Answers

You can use the @Nonbinding annotation for that purpose. You can force the container to ignore a member of a qualifier type by annotating the member @Nonbinding. Look at the following example:

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

Here the comment will be ignored when matching beans by the @PayBy qualifier. A reference to the CDI documentation describing this can be found here.

like image 111
Adrian Mitev Avatar answered Nov 03 '22 07:11

Adrian Mitev