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
0
votes
1 answer

Jersey + HK2: EntityManager injection fails

I'm following this advice to get an EntityManager injected into my Jersey + HK2 project. For some reason, I suddenly see this exception when starting the service: Exception in thread "main" java.lang.IllegalArgumentException: Creation of…
Hank
  • 4,597
  • 5
  • 42
  • 84
0
votes
1 answer

Problems with HK2 Inject

I'm currently using Jersey, Grizzly and Gradle in a web project and I'm attempting to get dependency injection working with HK2. I've followed the instructions in the documentation (https://hk2.java.net/2.5.0-b04/inhabitant-generator.html) for…
Vincent Catalano
  • 2,259
  • 4
  • 22
  • 29
0
votes
0 answers

Extended WADL support in Jersey 2 : Injection issue with Provider

I worked on a web application deployed in an OSGI environment (Equinox). The WAR is deployed in a Jetty 9 Bundle. The application is a JAX RS 2.0 application (Jersey 2) using Guice as injection framework. I use guice bridge to achieve this. I have a…
0
votes
0 answers

Java Deep Injection with custom annotations preferably with hk2

we have implemented a framework that uses hk2 with custom annotations to inject objects in our rest services classes. Now we want to inject objects also if the annotations are present inside the injected objects in a recoursive way. Is there a clean…
Mara
  • 41
  • 3
0
votes
1 answer

spring Integration kafka outboundchannel object Injection Error by glassfish

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 org.springframework.integration
shiv455
  • 7,384
  • 19
  • 54
  • 93
0
votes
1 answer

HK2 Inhabitant Generator: How to bind a factory to an annotated service?

I am using HK2 within my Jersey app. To bind classes I am using the inhabitant generator maven plugin. For one of my classes I need to use a factory to produce an instance. Binding the factory within my application class works as…
gorootde
  • 4,003
  • 4
  • 41
  • 83
0
votes
1 answer

Determine ServiceLocator has no user defined services

I'm trying to make a reusable component that creates a ServiceLocator from the services defined in the inhabitants file. I need to determine if the ServiceLocator has services apart from the built in ones. If it doesn't, maybe log some warning to…
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
0
votes
1 answer

JAX-RS @Context usage in Jersey 2 compared to Jersey 1

[EDIT] The problem is with the register(new ServiceBinder<>(MyService.class)); Jersey generates a warning and ignores the registration for all but the first one (Existing previous registration found for the type); it only considers the type-erased…
franck102
  • 221
  • 4
  • 14
0
votes
1 answer

HK2 InstantiationService nested inject

I m using hk2 as CDI engine. I have 2 nested injection as in the code below: public class Root { @Inject Son son; ... } public class Son { @Inject GrandSon gs; //should i put it here? ... } public class GrandSon { ... } These are the…
Alex
  • 1,515
  • 2
  • 22
  • 44
0
votes
1 answer

Injecting multiple child classes into service with Jersey and HK2

I have an abstract class AbstractTimerTask that extends TimerTask and I have a Jersey service that is going to manage these timer tasks. I will have more than one implementation of the abstract class, and I would like them all injected into the…
BamaPookie
  • 2,560
  • 1
  • 16
  • 21
0
votes
1 answer

ContainerRequestFilter with per-lookup-injectable not injected per request

I use Jersey 2 on a standalone Grizzly webserver. HK2 is used for CDI. I'd like to get a service with @PerLookup-scope injected into a jersey ContainerRequestFilter. The service: import org.glassfish.hk2.api.PerLookup; import…
Hank
  • 4,597
  • 5
  • 42
  • 84
0
votes
1 answer

Deploy war failure on glassfish 4.1

While deploying a war on Glassfish 4.1, I get the following error : Caused by: java.lang.NoClassDefFoundError: org/jvnet/hk2/internal/ServiceLocatorImpl at com.timm.mcr.api.guice.APIJerseyModule.configureServlets(APIJerseyModule.java:47) at…
ruddy32
  • 21
  • 7
0
votes
1 answer

Using Hk2 to generate an instance with the specified constructor args

I am using HK2 and the service locator pattern in my code. The following is the Interface: package org.swx.nursing.tools.sqlfinder.gui; import org.jvnet.hk2.annotations.Contract; import…
Rookie
  • 5,179
  • 13
  • 41
  • 65
0
votes
1 answer

Unit testing views in dropwizard (sequel)

As mentioned in a related post I am trying to test my resources in Dropwizard. The resources can both return json data and views. The latter work with freemarker templates. For testing paths which return views I extended the code of the dropwizard…
Bastian
  • 4,638
  • 6
  • 36
  • 55
0
votes
1 answer

Dependency Injection of Primitive Types (Decided at Runtime) With HK2

So basically, I have a situation where I want to inject primitive types into a class (i.e. a String and an Integer). You can think of a URL and port number for an application as example inputs. I have three components: Now say I have a class, which…
Nishant Kelkar
  • 412
  • 1
  • 4
  • 20
1 2 3
18
19