Dependency injection with Jersey 2.0

后端 未结 8 1118
遇见更好的自我
遇见更好的自我 2020-11-22 01:18

Starting from scratch without any previous Jersey 1.x knowledge, I\'m having a hard time understanding how to setup dependency injection in my Jersey 2.0 project.

8条回答
  •  死守一世寂寞
    2020-11-22 02:19

    Late but I hope this helps someone.

    I have my JAX RS defined like this:

    @Path("/examplepath")
    @RequestScoped //this make the diference
    public class ExampleResource {
    

    Then, in my code finally I can inject:

    @Inject
    SomeManagedBean bean;
    

    In my case, the SomeManagedBean is an ApplicationScoped bean.

    Hope this helps to anyone.

提交回复
热议问题