Call 1 jersey resource class from another Jersey resource class with @Context ServletContext

前端 未结 1 448
清酒与你
清酒与你 2021-01-04 20:48

I have Jersey resource class A calling a method in resource class B.Both classes have a @Context ServletContext servletContext at the class level. When I instantiate class B

相关标签:
1条回答
  • 2021-01-04 21:19

    You can instantiate class B using ResourceContext. I.e. in class A you can have:

    @Context private ResourceContext rc;
    

    And then in you can instantiate resource B as follows:

    B resourceB = rc.getResource(B.class);
    

    See ResourceContext javadoc for more info.

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