CDI interceptor injected into the Jersey RS (Resource) service not working?

So, I have a tomcat 8 + jersey 2.5.1 + CDI welding application that works very well in most cases. Where this fails, I cannot intercept the calls to the jersey resource method using the CDI interceptor. This makes sense because the jersey resource class is not a CDI bean. Then, is there a way to make a CDI interceptor work in a T-shirt? Another way to ask this question: can a CDI bean be used as a Jersey resource?

Thank!

EDIT: Before I wrote my RESTful resources using Jersey, I had CDI hookers that were used to start and complete database transactions. I really need to follow the same or similar pattern to implement this pass-through transaction in my RESTful resources. This is the main reason to ask this question.

Thanks again!

+3
source share
2 answers

Can a CDI bean be used as a Jersey resource?

Yes, but since Jersey DI is based on hk2 , not CDI, you need a bridge.

In a glass planet, such a bridge is implemented by the module jersey-gf-cdi:

<dependency>
    <groupId>org.glassfish.jersey.containers.glassfish</groupId>
    <artifactId>jersey-gf-cdi</artifactId>
    <version>2.6</version>
</dependency>

Tomcat ( , , Weld).

, 2.6 JNDI, "java: comp/BeanManager", Tomcat .

2.6 ( , ), CDI.current().getBeanManager().

Tomcat 7 , Tomcat 8.

+2

(CDI EJB) RESTful. , RESTful HttpHeaders, , CDI EJB. , RESTful HttpHeaders, - CDI, JSF, .

. , .

!

0

Source: https://habr.com/ru/post/1537039/


All Articles