问题
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
回答1:
As stated in The Spec
5.2.1 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 theApplication
subclass instance allows configuration information to be centralized in that class. Note that this cannot be injected into theApplication
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.
来源:https://stackoverflow.com/questions/29674831/get-the-jax-rs-application-a-resource-is-attached-on