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

InjectionResolver with Jersey 2.x -- Resource being called twice

I am attempting to figure out how to use a custom annotation and HK2 to inject something into a Resource method. Because I'm in a Spring webapp environment, I just piled on the existing helloworld-spring-webapp Jersey 2 example. My problem is, is…
Eric Miles
  • 141
  • 1
  • 6
5
votes
0 answers

How to fix "java.lang.IllegalArgumentException: interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader"

I am trying to override the Jersey (and dependency) libraries(v2.21) available in WebLogic 12.2.1 with application packaged ones which has Jersey v2.25.1. But end up with below: A MultiException has 4 exceptions. They…
Rajath
  • 51
  • 1
5
votes
2 answers

Can't solve this issue UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl

i've tried alot to fix this issue but couldn't. I find, if we use "abstractBinder" then this could be fix but once i've my Binder in place, i start having 404 error. UnsatisfiedDependencyException: There was no object available for injection at…
Nitin Gupta
  • 143
  • 4
  • 13
5
votes
0 answers

Weblogc 12.2.1.3 with jersey 2.0 error during deployment

Currently we have developed a jersey 2.0 restful application with the following frameworks: jaxrs-ri (2.25.1) spring4 (4.3.10) jersey-spring3 (2.25.1) The application works perfectly in tomcat 8.5 & Weblogic 12.1.x servers However, we got the…
Cube
  • 95
  • 2
  • 11
5
votes
1 answer

Inject dependencies into ServletContextListener using HK2 in Jersey

In order to initialize the application at startup, I extended ServletContextListener: @WebListener public class MyServletContextListener implements javax.servlet.ServletContextListener { @Override public void…
Vasiliy
  • 16,221
  • 11
  • 71
  • 127
5
votes
1 answer

Jersey Inject RequestScoped IllegalStateException

Been working on this one for hours and nothing seems to work. It's Jersey 2.23.2. The idea is that I want to inject a request based Hibernate Session into a Jersey provider to use in my REST API. Instead, I get this: javax.servlet.ServletException:…
ptoinson
  • 2,013
  • 3
  • 21
  • 30
5
votes
3 answers

Java: method-chaining and dependency injection

Is it acceptable to use method-chaining, when working with a service that is managed by a dependency injection framework (say HK2)? I'm unsure if it is allowed to "cache" the instance, even if its only within the scope of the injection. Example…
Hank
  • 4,597
  • 5
  • 42
  • 84
5
votes
1 answer

HK2 / Jersey does not Inject into non Resource class

I am using jersey to inject POJOs on various locations. Here is my config: register(new AbstractBinder() { @Override protected void configure() { bind(Bar.class).to(Bar.class).in(Singleton.class); …
gorootde
  • 4,003
  • 4
  • 41
  • 83
5
votes
1 answer

java.lang.noclassdeffounderror: org/glassfish/hk2/api/servicelocatorfactory$createpolicy

Why am I getting error even though I added all the required jars. I am trying to build rest client using JERSEY client=ClientBuilder.newClient(); response =…
saivinod
  • 51
  • 1
  • 2
  • 7
5
votes
2 answers

Using Jersey's Dependency Injection in a Standalone application

I have a interface here interface Idemo{ public int getDemo(int i); } And it's one implementation class DemoImpl implements Idemo{ @Override public int getDemo(int i){ return i+10; } } And there is a class which has a dependency on…
rakesh99
  • 1,234
  • 19
  • 34
5
votes
1 answer

Using a custom hk2 InjectionResolver to inject application configuration

Kind of a follow up to my previous question. I'm trying to inject application configuration data using JSR-330 standard annotations and the HK2 framework bundled with jersey. Ideally I'd like to create a custom InjectionResolver for the Named…
agnul
  • 12,608
  • 14
  • 63
  • 85
5
votes
1 answer

HK2 MethodInterceptor with Jersey resource

How can I set up an aop MethodInterceptor to work with Jersey resources? Here is what I've tried, following this documentation: Step 1 - InterceptionService public class MyInterceptionService implements InterceptionService { private final…
Alden
  • 6,553
  • 2
  • 36
  • 50
5
votes
3 answers

org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee

I am new to Jersey 2. So far I worked with Jersey 1.x and Spring and would like to use HK2 implementation. After reading the tutorial I wrote the following: @ManagedBean @Path("products") @Produces({ MediaType.APPLICATION_JSON }) public class…
Dejell
  • 13,947
  • 40
  • 146
  • 229
5
votes
2 answers

How do I configure HK2 to inject an object created by a factory method?

In HK2 the basic example code for configuring injection is this (within a class that extends AbstractBinder: bind(BuilderHelper .link(FooImpl.class) // the class of the object to be injected .to(FooInterface.class) // identifies what…
slim
  • 40,215
  • 13
  • 94
  • 127
4
votes
1 answer

How to fix "org.glassfish.jersey.inject.hk2.RequestContext.RequestContext must be in the Singleton scope"

I'd like to implement a simple REST-API with Jersey and grizzly. After beeing stuck in dependency-hell for a while, I ended up with an exception and I have no idea how to handle/interpret: java.lang.IllegalArgumentException: The implementation class…
MUmla
  • 445
  • 1
  • 8
  • 26
1 2
3
18 19