Create interceptor qualifier thats ignore annotation value()
Asked Answered
T

1

6

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.

Tachistoscope answered 16/4, 2013 at 21:6 Comment(0)
D
12

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.

Demonstrator answered 17/4, 2013 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.