Если я использую Джерси 1.12, и у меня есть несколько классов ресурсов, и всем им нужен доступ к некоторому общему контексту, как лучше всего внедрить зависимость, будь то в конструкторе для класса ресурсов или в метод обработчика? Нужно ли мне использовать внешнюю библиотеку DI, или в Джерси есть что-то встроенное?
т. е., возможно, ресурс для Foos выглядит так:
package com.example.resource;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
@Path("/some/api/path/foo")
public class FooResource
{
@GET
@Produces("text/html")
public String getFoo(@QueryParam("id") String id)
{
Foo foo = /* get a Foo from some shared context based on id */
/* Process foo into a String */
}
}
и для Bars:
package com.example.resource;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
@Path("/some/api/path/bar")
public class BarResource
{
@GET
@Produces("text/html")
public String getBar(@QueryParam("id") String id)
{
Bar bar = /* get a Bar from some shared context based on id */
/* Process bar into a String */
}
}