获取附加了资源的JAX-RS应用程序 [英] Get the JAX-RS application a resource is attached on

查看:82
本文介绍了获取附加了资源的JAX-RS应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能获得附加资源的JAX-RS Application的实例.理想情况下,不依赖于特定实现的方式.例如,使用依赖注入...

I wonder if it's possible to get an instance of the JAX-RS Application a resource is attached on. Ideally a way that isn't dependent to a specific implementation. For example using dependency injection...

非常感谢您的帮助, 蒂埃里

Thanks very much for your help, Thierry

推荐答案

5.2.1应用程序

可以使用@Context批注将应用程序提供的Application子类的实例注入到类字段或方法参数中.对Application子类实例的访问允许将配置信息集中在该类中.请注意,不能将其注入Application子类本身,因为这将创建循环依赖关系.

The instance of the application-supplied Application subclass can be injected into a class field or method parameter using the @Context annotation. Access to the Application subclass instance allows configuration information to be centralized in that class. Note that this cannot be injected into the Application subclass itself since this would create a circular dependency.

但是根据我的经验,它很可能不是实际实例,而是代理.另外,如果您要更改其中的任何内容,我不确定是否有可能.它可能是只读的.

but from I've experienced, it will most likely not be the actual instance, but a proxy. Also if you're looking to alter anything on it, I'm not sure it's possible. It might be read-only.

这篇关于获取附加了资源的JAX-RS应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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