Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register CDI interceptor without using beans.xml

I am searching for a way to load a given interceptor programmatically.

I've seen a way to dynamically set an interceptor binding for a given bean, but the interceptor for that binding must be defined in the beans.xml. I know I can use the @Interceptors annotation but that way I am tied to a specific implementation.

Is there a way to load an interceptor (probably through a CDI extension)? Or a way to make interceptors enabled by default without the need to declare the <interceptors></interceptors>?

I am using Weld-1.1.24

like image 600
Miro Avatar asked Jan 28 '23 07:01

Miro


1 Answers

For anyone coming here via a search, like I did, and not being limited to CDI 1.0:
You can add an @Priority() annotation to your interceptor so you don't have to to add it to the beans.xml

@MyAnnotation @Interceptor @Priority(Interceptor.Priority.LIBRARY_BEFORE)
public class MyAnnotationInterceptor{...}
like image 135
sacnoth Avatar answered Feb 13 '23 04:02

sacnoth