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:

MyResource.java :

  class MyResource {@Context StorageEngine storage; [...]}  

In the StorageEngineProvider.java :

@Provider class applies StorageEngineProvider ContextResolver & lt; StorageEngine & gt; {Private Storage Engine Storage = New Inomerative Engine (); Public Storage Engine getContext (class

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  storage  in my resource class is always  null  - No  Manufacturer of StorageEngineProvider    / code> and its  getContext  method 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

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -