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

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

问题描述

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.

解决方案

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.

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

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