hk2

How do I properly configure an EntityManager in a jersey / hk2 application?

女生的网名这么多〃 提交于 2019-11-26 09:57:18
问题 I have a jersey-2 / hk2 application which uses JPA persistence. The EntityManager is bound at startup like this public MyApplication() { // ... register(new AbstractBinder() { @Override public void configure() { bindFactory(EmFactory.class) .to(EntityManager.class) .in(RequestScoped.class); } }); } with the factory class being public class EmFactory implements Factory<EntityManager> { private static final String PERSISTENCE_UNIT = \"unit\"; private EntityManagerFactory emf; private

Jersey 2.x Custom Injection Annotation With Attributes

非 Y 不嫁゛ 提交于 2019-11-26 07:39:29
问题 I am in the process of migrating from DropWizard 0.7.1 to 0.8.1. This includes migrating from Jersey 1.x to 2.x. In my implementation that uses Jersey 1.18.1, I had a MyProvider (changed all class names for simplicity\'s sake) that implements InjectableProvider . This class would create MyInjectable objects, containing the custom injection annotation, MyToken . MyToken contains various attributes that are passed on and read by MyInjectable . Lastly, in the Application class I register a new

Dependency injection with Jersey 2.0

混江龙づ霸主 提交于 2019-11-25 22:27:28
问题 Starting from scratch without any previous Jersey 1.x knowledge, I\'m having a hard time understanding how to setup dependency injection in my Jersey 2.0 project. I also understand that HK2 is available in Jersey 2.0, but I cannot seem to find docs that help with Jersey 2.0 integration. @ManagedBean @Path(\"myresource\") public class MyResource { @Inject MyService myService; /** * Method handling HTTP GET requests. The returned object will be sent * to the client as \"text/plain\" media type.