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

How can I determine if I'm inside Jersey request scope?

I have some code that will run both inside Jersey request context and outside of Jersey request context (in another thread). I have a piece of data I want to access in both cases that's optional, but I need to know if I can pull it from. Within…
Cameron Little
  • 3,487
  • 23
  • 35
3
votes
0 answers

ServiceLocatorImpl shutdown issue in Jersey 2.34

We've been getting errors occasionally from our test and production environments where ServiceLocatorImpl has shut down which causes it to fail to create stateless EJBs from any @Schedule methods. javax.ejb.EJBException: javax.ejb.EJBException:…
Tim
  • 181
  • 1
  • 8
3
votes
1 answer

Not able to inject @Service and @Contract dependency in my resource class

On base of the guide from this blog, Roll your own Auto Discovery with Jersey and HK2, I have the follow resource POJO: @Path("Test") public class TestResource { @Inject private TestService service; @GET …
Rui
  • 3,454
  • 6
  • 37
  • 70
3
votes
0 answers

Unknown HK2 failure Multiexception

I'm getting the following error: org.glassfish.jersey.internal.Errors logErrors WARNING: The following warnings have been detected: WARNING: Unknown HK2 failure detected: MultiException stack 1 of 1 java.lang.NoSuchMethodError:…
Flama
  • 772
  • 3
  • 13
  • 39
3
votes
1 answer

Wildfly 15 and Jersey - Trying to register multiple service locators into single service locator application

We are investigating moving an application currently working on Weblogic to Wildfly 15.0.1.Final. Our project is an ear which contains multiple wars, two of which are making use of Jersey (2.27) for restful webservices. These are an 'api' war and a…
ijm3
  • 71
  • 1
  • 8
3
votes
1 answer

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

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…
vikarjramun
  • 1,042
  • 12
  • 30
3
votes
0 answers

HK2 + Jersey 2.24 + JPA/Hibernate 5.2.4.Final EntityManager Inject on Tomcat- There was no object available for injection at SystemInjecteeImpl

I'm trying to implement dependency injection in EntityManager, but the following error occurs: ADVERTÊNCIA: The following warnings have been detected: WARNING: Unknown HK2 failure detected: MultiException stack 1 of…
3
votes
1 answer

Injection of type parameter in a generic class with HK2

I'm currently playing with HK2 2.5.0-b05 (which is the version used by Jersey 2.24) and I'm unable to perform a specific type of injection. I was able to generalize my issue and I came up with a simple, small test case. The code is the…
fabriziocucci
  • 782
  • 8
  • 20
3
votes
1 answer

CDI Weld omit @Inject

Having class like so: public class A { @Inject B b; @Inject C c; } is it possible to tell Weld NOT to inject into c? I can veto A class using event: void processAnnotatedType(@Observes ProcessAnnotatedType pat) but then also B…
maciek
  • 83
  • 7
3
votes
1 answer

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

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…
Jaap Dekkers
  • 33
  • 1
  • 4
3
votes
2 answers

Jersey HK2 injection in manually created objects

Is there any way to inject dependencies into manually created objects? public class MyCommand { @Inject Repository repository; } public Repository { @Inject EntityManager em; } MyCommand command = new MyCommand(); Repository is properly…
Fleigm
  • 53
  • 1
  • 4
3
votes
1 answer

Jersey 2 + HK2 - @ApplicationScoped not working

I have class @ApplicationScoped public class Service{ private Map something ; private final Logger LOGGER = LoggerFactory.getLogger(Service.class); @PostConstruct public void initialize(){ something = new HashMap<>(); } …
deem
  • 1,252
  • 1
  • 19
  • 38
3
votes
1 answer

HK2 does not see Spring Beans

I have a Spring Boot application with Jersey 2 REST services. Spring Boot seems to initialize correctly and I have Jersey Spring bridge ('org.glassfish.jersey.ext:jersey-spring3:2.22.2'). Despite this the following error is thrown then REST…
Sergey
  • 3,253
  • 2
  • 33
  • 55
3
votes
1 answer

Testing Jersey app, Injecting classes using Jersey Injection built-in framework (HK2)

I need to create tests for some class. This class in main project (src/main/java/..) is injected easily into another classes, since I have custom ResourceConfig class which declares which packages have to be scanned to seek for service classes. Now…
azalut
  • 4,094
  • 7
  • 33
  • 46
3
votes
1 answer

HK2 TypeLiteral and wildcards

I'm trying to use Jersey with HK2. I need to bind really weird type: List> So I have my binder defined as follows: resourceConfig.register(new AbstractBinder() { …
Jan Zyka
  • 17,460
  • 16
  • 70
  • 118