I am trying to figure out how to use custom annotation and HK2 to input something into the Resource method. Because I'm in the Spring webapp environment, I just bumped into an existing helloworld-spring -webapp Jersey 2 example. My problem is that the Resource method is called twice. The first time the injection is successful, the second time it is not.
InjectionResolver.resolve () Method
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> root) {
return "THIS HAS BEEN INJECTED APPROPRIATELY";
}
Binder.configure () Method
@Override
protected void configure() {
bind(SampleInjectionResolver.class).to(new TypeLiteral<InjectionResolver<SampleParam>>() {}).in(Singleton.class);
}
ResourceConfig binder registration
public MyApplication () {
register(new SampleInjectionResolver.Binder());
...
JerseyResource.getHello ()
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getHello(@SampleParam String inject) {
System.err.println("EXECUTING!");
System.err.println("*******************************INJECTED: " + inject);
return inject;
}
Deriving a Server from a SINGLE Call
EXECUTING!
*******************************INJECTED: THIS HAS BEEN INJECTED APPROPRIATELY
EXECUTING!
*******************************INJECTED:
Am I missing a configuration somewhere? I can’t understand why his name is twice. I assume that if I fix this, a problem with InjectionResolver not working on the second call would be a problem without problems.