我已经到处搜索了,但似乎找不到清晰的答案...
服务器(我的问题是glassfish)注入带有@Context注释的实际对象的机制是什么?更具体地说,如果我想编写一个类来执行以下操作:
@Path("/")
public class MyResource {
@GET
public String doSomething(@Context MyObject obj) {
// ...
}
}
那么我该怎么做呢?MyObject在哪里被实例化,由谁负责实例化,以及如何实例化?编辑:我看到过类似以下内容的东西: 在JAX-RS中使用@Context、@Provider和ContextResolver 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 )
this.getSingletons().add(new MyObjectProvider());
将提供程序注册。 - justin