Questions tagged [hk2]

HK2 is a light-weight and dynamic dependency injection framework for Java.

  • HK2 is JSR-330 compliant and has useful utilities for marking classes as services and interfaces as contracts. JSR-330 defines services and injection points that can be dynamically discovered at runtime and which allow for Inversion of Control (IoC) and dependency injection (DI).

  • HK2 provides an API for fine control over its operation and has the ability to automatically load services into the application. It is the foundation for the GlassFish V3 and V4 application servers as well as other products.

  • HK2 also has a powerful API that can be used to perform several tasks such as binding service descriptions into the system and looking up services, as well as several extensibility features allowing the users to customize or change the behavior of HK2.

The following list gives an overview of some of the things that can be customized or extended with HK2:

  • Custom scopes
  • The use of proxies
  • Custom injection resolution
  • Assisted injection
  • Just In Time injection resolution
  • Custom validation and security
  • Run Level Services
285 questions
8
votes
2 answers

No ServiceLocatorGenerator installed Error while Running Tests in Dropwizard

I have upgraded Dropwizard in my project and facing issue while running unit tests, although service start up works fine and all APIs are behaving normally, problem is coming only while running tests, here are my versions: Dropwizard: 1.1.0 Jersey:…
user2098324
  • 972
  • 10
  • 17
8
votes
3 answers

Jersey 2 + HK2 - automatic binding of classess

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…
deem
  • 1,252
  • 1
  • 19
  • 38
8
votes
1 answer

Getting Jersey 1.x and 2.x to coexist

I've got a Dropwizard project (using Jersey 2.x) where I need to use another library that has a dependency on jersey-client from 1.x and I'm having some trouble getting both to coexist on the classpath. It looks like what is happening is that HK2…
Will Gorman
  • 869
  • 1
  • 7
  • 16
8
votes
1 answer

@Immediate annotation use in Jersey2

I have a similar issue to the one raised here: How do I get my Jersey 2 Endpoints to eagerly initialize on startup? But slightly further down the line. I can get my resource immediately loaded, but when I try to use it by calling the REST url, I…
Phil
  • 141
  • 2
  • 7
7
votes
1 answer

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

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() { …
agnul
  • 12,608
  • 14
  • 63
  • 85
7
votes
5 answers

Jersey Hk2 injecting @Service annotated classes

For the life of me I cannot get Jersey with hk2 to automatically discover @Service annotated classes and inject them. I have tried to follow every advice on stack overflow, jersey and hk2 documentation and still no luck. I am trying to inject a…
Daniel David Kovacs
  • 226
  • 1
  • 2
  • 13
7
votes
3 answers

How does ServiceLocator find @Service and @Contact automatically in HK2?

According to HK2 @Service javadoc Annotation placed on classes that are to be automatically added to an hk2 ServiceLocator. I don't know how to make ServiceLocator find annotated classes automatically. TestService @Contract public interface…
Rangi Lin
  • 9,303
  • 6
  • 45
  • 71
7
votes
1 answer

Jersey + HK2 + Grizzly: Proper way to inject EntityManager?

I've managed to set up injection (into resource classes) of my own service classes in Jersey, HK2 and a plain GrizzlyServer. (Basically followed this example.) I'm now curious what the best is to inject JPA EntityManagers into my resource classes?…
aioobe
  • 413,195
  • 112
  • 811
  • 826
6
votes
1 answer

Dropwizard HK2 injection

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…
Materno
  • 343
  • 8
  • 20
6
votes
2 answers

How to get HK2 ServiceLocator in a Jersey2 ServletContainer?

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…
Laurent Grégoire
  • 4,006
  • 29
  • 52
6
votes
1 answer

Jersey custom method parameter injection with inbuild injection

Hello I am building an application using dropwizard, that is using jersey 2.16 internally as REST API framework. For the whole application on all resource methods I need some information so to parse that information I defined a custom filter like…
Syed
  • 1,461
  • 3
  • 19
  • 37
6
votes
1 answer

HK2 What is the proper way to override bindings of another AbstractBinder

I come from the guice world and am looking for a way to do something similar to the Modules.override provided by Guice. I have a pattern where I create a base Module/AbstractBinder for my production and then in test I override the bindings that need…
Chris Hinshaw
  • 6,967
  • 2
  • 39
  • 65
6
votes
1 answer

Registering a custom ResourceMethodInvocationHandler in Jersey

I am attempting to intercept a resource call after it's JSON has been unmarshalled. Reading through some forums and posts I discovered that I may be able to do so by implementing…
jmdev
  • 181
  • 2
  • 10
6
votes
3 answers

What corresponds to asEagerSingleton in HK2 in Jersey 2?

I am developing a REST API using Jersey 2 and I need some of my classes to be instantiated on start up and not just when some resource request triggers it. So what I am asking is: how do I achieve that an instance of SomethingImpl defined below here…
Stine
  • 1,605
  • 5
  • 23
  • 44
6
votes
1 answer

Two custom injection annotations in Jersey 2

How should I do the ValueFactoryProvider binding in order to have two custom injection annotations coexist in Jersey 2? Below I have included an example of my current approach and as you can see the Hello annotation injection "hides" the SmallTalk…
Stine
  • 1,605
  • 5
  • 23
  • 44
1
2
3
18 19