Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HK2 binder registered in Feature is ignored #3675

Open
jerseyrobot opened this issue Sep 19, 2017 · 7 comments
Open

HK2 binder registered in Feature is ignored #3675

jerseyrobot opened this issue Sep 19, 2017 · 7 comments
Labels

Comments

@jerseyrobot
Copy link
Contributor

Description

Given the major breaking change around Jersey DI, I have spent some time today in the attempt to migrate a simple web app based on Jersey 2.25.1 to Jersey 2.26.

The web app contains a ResourceConfig which registers:

  1. a org.glassfish.hk2.utilities.binding.AbstractBinder;
  2. a javax.ws.rs.core.Feature which, in turn, registers another org.glassfish.hk2.utilities.binding.AbstractBinder.

Since I'm heavily relying on HK2-specific annotations, I tried to add jersey-hk2 as a dependency of the web app but the following came out:

  • the binder at 1 is configured (i.e. its configure method is invoked during startup);
  • the binder at 2 is not configured (i.e. its configure method is not invoked during startup).

If I replace org.glassfish.hk2.utilities.binding.AbstractBinder with org.glassfish.jersey.internal.inject in 2, also that binder is properly configured.

I guess (and hope) that depending on jersey-hk2 should be sufficient to consistently register HK2 binders either directly on a ResourceConfig and indirectly through Features.

Test

@jerseyrobot
Copy link
Contributor Author

@fabriziocucci Commented
Added test that shows the issue.

@jerseyrobot
Copy link
Contributor Author

@sergey-morenets Commented
Hi

Do you have any estimates on this issue? It prevents our project to migrate to 2.26.

Thanks.

@jerseyrobot
Copy link
Contributor Author

@sergey-morenets Commented
@fabriziocucci

Hi

I tried to reproduce your use case and it worked only if I use Feaure + Binder(org.glassfish.jersey.internal.inject.AbstractBinder)
If I registered my Binder(org.glassfish.jersey.internal.inject.AbstractBinder) directly in my ResourceConfig then configure method is not invoked.

@jerseyrobot
Copy link
Contributor Author

@fabriziocucci Commented
@sergey-morenets I don't seem to be able to replicate your results, i.e. I can see the Jersey binder working properly!

I've just updated my test to include the following use cases:

  • Jersey binder registered on ResourceConfig (working);
  • Jersey binder registered on FeatureContext (working);
  • HK2 binder registered on ResourceConfig (working);
  • HK2 binder registered on FeatureContext (NOT working).

It may very well be that you are hitting some other issue or there is something else in your test.

@jerseyrobot
Copy link
Contributor Author

@xavier-b Commented
Hi,
Maybe there is a link with :
Features are initialized before the SpringComponentProvider #3795

@jerseyrobot
Copy link
Contributor Author

@ccobham
Copy link

ccobham commented Jul 22, 2018

Hello,

I encountered the same issue and was unable to use the Jersey org.glassfish.jersey.internal.inject.AbstractBinder implementation since we use HK2 outside of a Jersey context in certain cases.

As a workaround, I injected an instance of org.glassfish.hk2.api.ServiceLocator into each Feature, then registered the org.glassfish.hk2.utilities.binding.AbstractBinder directly on the locator via org.glassfish.hk2.utilities.ServiceLocatorUtilities#bind:

public class FooFeature implements Feature {
   
   private ServiceLocator locator;

   @Inject
   public FooFeature(ServiceLocator locator) {
      this.locator = locator;
   }

   @Override
   public boolean configure(FeatureContext context) {
      ServiceLocatorUtilities.bind(locator, new FooBinder());
      return true;
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants