java - Using @Context, @Provider and ContextResolver in JAX-RS -
I am getting acquainted with implementing RAS web services in Java and I ran into the following problem. One of my resource classes needs access to the storage backend, which is far behind the StorageEngine interface. I want to inject the existing StorageEngine example in the processing class related to REST requests and I thought that a good way to do this is @Context annotation and a suitable contextualsolar class. This is what I have done so far:
class MyResource {@Context StorageEngine storage; [...]} In the StorageEngineProvider.java :
I automatically use the com.sun.jersey.api.core.PackagesResourceConfig to search providers and resource classes, and according to logs I'm doing this, the CodeEngineProvider raises the class well (timestamps and unnecessary things are deliberately left):
INFO: Root resource classes found: class MyResource information: Provider class found: However, the value of/ code> and itsstoragein my resource class is alwaysnull- NoManufacturer of StorageEngineProvidergetContextmethod is called by jersey, anytime what is wrong here Am doing
I do not think there is a JX-RS specific way to do this: What do you want? The nearest work must be done:
@ path ("/ some /") range MyResource {@ Context javax.ws.rs.ext.Providers providers; Get @GET Public Relations () {Reference Resolver & lt; Storage Engine & gt; Resolver = Provider.Get ContextroSolar (Storage Agency, MediaType, wildcard card); Storage Engine Engine = Reseller.Gate (StorageEngine.Class); ...}} However, I think that @javax.ws.rs.core.Context annotations and javax.ws.rs.ext.ContextResolver are actually JX-RSS and JAX -Support the RS providers.
You guide the Java Context and Dependency Injection (JSR-299) implementation (which should be available in Java EE6) or other dependency injection frameworks such as Google to help you.
Comments
Post a Comment