How to integrate JAX-RS with CDI in a Servlet 3.0 container

后端 未结 3 2075
失恋的感觉
失恋的感觉 2020-12-16 18:32

I have a web application running on a Servlet 3.0 container (Jetty 9.0.4) using JSF 2.2 (Mojorra 2.1.3) & CDI 1.1 (Weld 2.0.3). No full-fledged application server is use

相关标签:
3条回答
  • 2020-12-16 19:19

    I solved my problem.

    The problem is, that Jersey JAX-RS implementation uses the HK2 dependency injection framework and this framework is simply not aware of the CDI beans. And by following the idea of the accepted answer in this post, I make the CDI beans available for the HK2 injection bindings and the injection of my application scoped beans works fine now.

    But I really wonder why it is so cumbersome to bring together two constituent parts of Java EE.

    Update: As G. Demecki mentioned in a comment, this is solution is no longer needed! But it helped me out at the time of asking this question.

    0 讨论(0)
  • 2020-12-16 19:27

    You can just include this dependency to enable Jersey-CDI integration

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

    It works for me using Jersey 2.8, Jetty 9.1 and Weld 2.2.0.SP1.

    0 讨论(0)
  • 2020-12-16 19:31

    I have created a sample project with Embedded Jetty, Jersey 2 and CDI https://drive.google.com/file/d/0B9j0dIS5bS0wSEg0NTk2eGpPSGs/view?usp=sharing

    Kindly let me know if you find any issues

    0 讨论(0)
提交回复
热议问题