hk2

Java/Jersey - creating own injection resolver with ParamInjectionResolver - strange behavior

南笙酒味 提交于 2019-12-06 06:12:37
I am trying to create an injection resolver. I have a data class: public class MyData { ... } I have the following annotation: @Target({ElementType.FIELD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface MyDataInject { } My injection resolver looks like this: public class MyDataInjectionResolver extends ParamInjectionResolver<MyDataInject> { public MyDataInjectionResolver () { super(MyDataValueFactoryProvider.class); } @Singleton public static class MyDataValueFactoryProvider extends AbstractValueFactoryProvider { @Inject public

How do I get a reference to the Jackson Object Mapper in a jersey2 / hk2 application

谁说胖子不能爱 提交于 2019-12-05 19:21:46
问题 I have a jersey2 application configured for JSON support via Jackson, adding <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>${jersey.version}</version> </dependency> in the POM file and public MyApplication() { ... register(JacksonFeature.class) ... } in my application. Everything works, my resources get deserialized POJOs as arguments @POST @Consumes(MediaType.APPLICATION_JSON) public void blah(MyPojo p) { ... } Now one

Jersey 2 + HK2 - automatic binding of classess

吃可爱长大的小学妹 提交于 2019-12-05 11:35:42
Continuation of topic Jersey 2 + HK2 - @ApplicationScoped not working . I already know, how to bind classes in order to @Inject them properly. Do you have any ideas, how to automize this process? Putting every single service in bind statements seems like very bad smell in my application. After using Google's Guice for a number of years, I am accustomed to the availability of a Just-In-Time binder, allowing the injection of arbitrary types without requiring any upfront configuration. I too found the idea of having to explicitly bind every service to be a bad code smell. I'm also not crazy about

HK2 annotations not being handled

大憨熊 提交于 2019-12-04 17:28:56
I'm using HK2 through Jersey, and am looking to get @Immediate services working. In the process, I notice that (as it seems) none of the annotations for my services are getting registered. E.g., after spinning up my ServiceLocator and looking at my descriptor for a service annotated with @Singleton, it is still set as @PerLookup. My code for initiating my application handler is below: ApplicationHandler handler = new ApplicationHandler(resourceConfig, new AbstractBinder() { ... }); My binder registers a service like so: bindAsContract(ShouldHaveSingletonScope.class); Looking at my

Jersey 2.26 and Spring 4.3.10 but no HK2

隐身守侯 提交于 2019-12-04 05:58:36
问题 Is it possible to configure Jersey 2.26.x that it solely depends on Spring for injection instead of HK2? I know Jersey is nowadays compatible with Spring, but is it also possible to get completely rid of HK2? 回答1: No it isn't. Jersey uses many special features of hk2 (such as good integration with Spring and Guice) in order to function 来源: https://stackoverflow.com/questions/45620576/jersey-2-26-and-spring-4-3-10-but-no-hk2

How do I get a reference to the Jackson Object Mapper in a jersey2 / hk2 application

痞子三分冷 提交于 2019-12-04 03:49:28
I have a jersey2 application configured for JSON support via Jackson, adding <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>${jersey.version}</version> </dependency> in the POM file and public MyApplication() { ... register(JacksonFeature.class) ... } in my application. Everything works, my resources get deserialized POJOs as arguments @POST @Consumes(MediaType.APPLICATION_JSON) public void blah(MyPojo p) { ... } Now one of thoese resources needs a reference to Jackson's ObjectMapper to do some deserialization on its own.

Dropwizard HK2 injection

谁都会走 提交于 2019-12-01 23:10:40
问题 im pretty new in working with dropwizard. Currently I'm trying to implement the HK2 dependency injection. That works pretty fine inside a resource but it doesn't work outside of a resource. Here is what I'm doing: Client client = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration()).build("contentmoduleservice"); //DAOs ContentModuleDAO contentModuleDAO = new ContentModuleDAO(hibernate.getSessionFactory()); ModuleServedDAO moduleServedDAO = new

Dropwizard HK2 injection

我与影子孤独终老i 提交于 2019-12-01 22:29:45
im pretty new in working with dropwizard. Currently I'm trying to implement the HK2 dependency injection. That works pretty fine inside a resource but it doesn't work outside of a resource. Here is what I'm doing: Client client = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration()).build("contentmoduleservice"); //DAOs ContentModuleDAO contentModuleDAO = new ContentModuleDAO(hibernate.getSessionFactory()); ModuleServedDAO moduleServedDAO = new ModuleServedDAO(hibernate.getSessionFactory()); //Manager ContentModuleManager moduleManager = new

Using a custom hk2 InjectionResolver to inject application configuration

只愿长相守 提交于 2019-12-01 06:06:43
Kind of a follow up to my previous question . I'm trying to inject application configuration data using JSR-330 standard annotations and the HK2 framework bundled with jersey. Ideally I'd like to create a custom InjectionResolver for the Named annotation, which will lookup the desired values in a Map or Properties object that I will populate from data read elsewhere. In my first attempt I've created an Application instance like public class MyApplication extends ResourceConfig { ... packages(MY_PACKAGES); property(MY_CONFIG_PROPERTY, someValue); register(new AbstractBinder() { @Override

jersey + grizzly + hk2: Dependency injection, but not into resource

送分小仙女□ 提交于 2019-12-01 04:33:43
Following up on Jersey + HK2 + Grizzly: Proper way to inject EntityManager? , I would like to understand how it is possible use dependency injection in classes which are not jersey resources . As an example, I might have background tasks running in an ExecutorService, and they might need an EntityManager. If I attempt to @Inject the EntityManager into the class, nothing happens. Injecting it into a @Path -annotated jersey resource class, injecting works fine. The application is running as a standalone JVM, not on a Java EE application server. Update: I have created a test scenario to