hk2

Guice nullpointer exception on injected instance

六眼飞鱼酱① 提交于 2019-12-10 18:46:51
问题 I'm using Guice in Jersey2 for DI (i want to use it so i can use Google App Engine -> not working with HK2). My ApplicationResource: public class ApplicationResource extends ResourceConfig { private static final Logger LOGGER = null; public ApplicationResource() { System.out.println("Application startup"); // Register resources and providers using package-scanning. packages("com.crawler.c_api"); // Register my custom provider - not needed if it's in my.package. register(ResponseCorsFilter

How do I configure HK2 to inject an object created by a factory method?

烈酒焚心 提交于 2019-12-10 17:17:42
问题 In HK2 the basic example code for configuring injection is this (within a class that extends AbstractBinder : bind(BuilderHelper .link(FooImpl.class) // the class of the object to be injected .to(FooInterface.class) // identifies what @Inject fields to link to .build()); This causes HK2 to call the constructor FooImpl() when it needs to create a FooInterface . What if FooImpl doesn't have a constructor? What if it's intended to be instantiated with a static factory method FooImpl.getInstance(

How to get HK2 ServiceLocator in a Jersey2 ServletContainer?

人走茶凉 提交于 2019-12-10 16:46:46
问题 I'd like to get Jersey2 and Guice to cooperate together, which is apparently rather difficult. I've seen some solution to this involving using the HK2-to-Guice bridge. But the bridge rely on getting the HK2 ServiceLocator instance in the init() of a custom Jersey2 ServletContainer in order to initialize GuiceBrige : public class MyServletContainer extends ServletContainer { @Override public void init() { ServiceLocator sloc = getApplicationHandler().getServiceLocator(); ... } } But somehow in

Registering Dropwizard configuration with Jersey 2 (HK2) DI

倾然丶 夕夏残阳落幕 提交于 2019-12-10 12:22:45
问题 In my Dropwizard (1.2.4) application I'm having trouble injecting my Dropwizard configuration into classes that are instantiated by HK2. What's the best way to achieve this? 回答1: Just bind the configuration instance . @Override public void run(final DummyConfiguration conf, Environment env) { env.jersey().register(new AbstractBinder() { @Override public void configure() { bind(conf).to(DummyConfiguration.class); } }) } Now you can @Inject the DummyConfiguration anywhere you need it. 来源: https

spring Integration kafka outboundchannel object Injection Error by glassfish

五迷三道 提交于 2019-12-10 11:54:12
问题 Added @ImportResource("classpath:outbound-kafka-integration.xml") on top of my SpringConfig class where i create beans in Java code... Added below dependency in pom.xml <dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-kafka</artifactId> <version>1.3.0.RELEASE</version> </dependency> it gives the below error when im debugging from SOAP UI client(my application is rest api)... MultiException stack 1 of 4 org.glassfish.hk2.api

Jersey HK2 Dependency Injection doesn't work after update to v2.27

故事扮演 提交于 2019-12-08 08:22:26
I have a project using Jersey v2.25.1. I was using Jersey's inbuilt HK2 injection to perform dependency injection, and everything worked fine. Fast forward to now, I decided to update to Jersey v2.27. When I ran my project, I got the following exception: java.lang.IllegalStateException: InjectionManagerFactory not found After some googling, I found that I needed to add the jersey-hk2 dependency. Doing so made me get the following exception: org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=<MyClass>,parent=

Jersey Test Framework & HK2-Guice bridge

99封情书 提交于 2019-12-08 05:22:44
问题 There are REST web service based on Jersey 2.23.2 & Guice 3.0. To use Guice it is necessary to adjust the hk2-guice bridge (I'm using 2.5.0-b07). Everything works fine until I have tried to test the service using Jersey Test Framework. Can't configure hk2-guice bridge for tests. My test: public class SomeTest extends JerseyTestNg.ContainerPerClassTest { @Override protected TestContainerFactory getTestContainerFactory() throws TestContainerException { return new GrizzlyWebTestContainerFactory(

REST API using Jersey 2

放肆的年华 提交于 2019-12-08 02:01:39
问题 I would like to implement a REST API using Jersey 2 and I would like to have resources separated into interfaces and their implementations like e.g.: @Path("hello") public interface HelloLogic { @GET @Produces("application/json") public String hello(); } public class HelloLogicResource implements HelloLogic { public String hello() { return "{\"reply\": \"Hello\"}"; } } I do not have any luck getting the resources exposed though. For the hello resource just mentioned I was hoping that the

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

笑着哭i 提交于 2019-12-07 18:58:22
问题 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

HK2 annotations not being handled

点点圈 提交于 2019-12-06 11:17:22
问题 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