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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With