我一直在到處尋找,但似乎無法找到一個明確的答案......哪裏@Context對象來自
什麼機制,使一臺服務器(GlassFish的我的問題)注入實際OBJETS是用@Context註釋?更具體地說,如果我想寫一個類似做類似的事情:
@Path("/")
public class MyResource {
@GET
public String doSomething(@Context MyObject obj) {
// ...
}
}
那麼我該怎麼做呢? MyObject的實例在哪裏?誰在做什麼?如何?
編輯:我見過的東西,如下列:
Using @Context, @Provider and ContextResolver in JAX-RS
http://jersey.576304.n2.nabble.com/ContextResolver-confusion-td5654154.html
然而,這不符合我所看到的廣場,如在org.neo4j.server.rest.web.RestfulGraphDatabase的構造,它具有以下特徵:
public RestfulGraphDatabase(
@Context UriInfo uriInfo,
@Context Database database,
@Context InputFormat input,
@Context OutputFormat output,
@Context LeaseManager leaseManager)
如果你是子類化javax.ws.rs.core.Application,你可以在你的應用程序的構造函數中用'this.getSingletons()。add(new MyObjectProvider());'註冊提供者。 – justin
鏈接已損壞。 –
試試這些:https://jersey.java.net/nonav/apidocs/1.19/jersey/com/sun/jersey/spi/inject/SingletonTypeInjectableProvider.html https://jersey.java.net/nonav/apidocs /1.19/jersey/com/sun/jersey/spi/inject/PerRequestTypeInjectableProvider.html – elanh