从另一个Jersey资源类调用1泽西资源类与@Context ServletContext [英] Call 1 jersey resource class from another Jersey resource class with @Context ServletContext

查看:138
本文介绍了从另一个Jersey资源类调用1泽西资源类与@Context ServletContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Jersey资源类A调用资源类B中的方法。这两个类在类级别有一个@Context ServletContext servletContext。当我实例化B类使用它的空构造函数从资源类A调用它时,servletContext在调用的B类方法中为null。有没有任何Jersey框架方法我可以调用类B,但有servletContext保留其值/属性从A类。

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 to call it from resource class A using its empty constructor, servletContext is null in the class B method being called. Is there any Jersey framework way I can call class B and yet have the servletContext retain its values/attributes from class A.

推荐答案

您可以使用ResourceContext实例化B类。也就是说在A类中你可以有:

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

@Context private ResourceContext rc;

然后在你可以实例化资源B如下:

And then in you can instantiate resource B as follows:

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

请参阅 ResourceContext javadoc 了解更多信息。

这篇关于从另一个Jersey资源类调用1泽西资源类与@Context ServletContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆