Jersey Client v 2
I used dependency :
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.16</version>
</dependency>
and it is working fine with that :
Maybe you should change your dependency version.
Hope that helps you:)
Jersey HK2 Dependency Injection doesn't work after update to v2.27
Answer by Paul Samsotha in a comment:
Try to change your AbstractBinder import. There are two, a Jersey one and an HK2 one. Try to use the Jersey one.
Basically, I needed to change the AbstractBinder class I implemented from
org.glassfish.hk2.utilities.binding.AbstractBinder
to
org.glassfish.jersey.internal.inject.AbstractBinder
The difference is that Jersey decoupled HK2 from it's internal DI mechanism in version 2.26, and thus, I needed to use the new AbstractBinder import, which comes directly from Jersey, and not HK2.
There are a few API differences: for instance, instead of a Factory<T>
, bindFactory()
takes a java.util.function.Supplier<T>
.
Is it possible to use Jersey without DI container?
No, it's not possible. Jersey only has an SPI for its dependency injection provider. It needs an implementation for it to run. Same way like JAX-RS is just a specification, but it needs an implementation (like Jersey or RESTEasy) to run. This is exactly the same thing. Jersey uses a lot of dependency injection internally, so the core code uses a facade for DI in its codebase. And we need to provide the underlying implementation for it to run. The implementations currently available, as you seen to understand, are HK2 and CDI (jersey-hk2
and jersey-cdi2-se
). I'm sure you've seen this post
Related Topics
Converting a Java Keystore into Pem Format
Return Generated PDF Using Spring MVC
File Upload with Java (With Progress Bar)
Retrieve Version from Maven Pom.Xml in Code
Ignoring Ssl Certificate in Apache Httpclient 4.3
Why Are Data Transfer Objects (Dtos) an Anti-Pattern
Convert Java.Time.Localdate into Java.Util.Date Type
Naming Threads and Thread-Pools of Executorservice
Jpa: How to Have One-To-Many Relation of the Same Entity Type
Good Reasons to Prohibit Inheritance in Java
@Aspectj Pointcut for All Methods of a Class with Specific Annotation
Increasing the Jvm Maximum Heap Size for Memory Intensive Applications
Is There a Fixed Sized Queue Which Removes Excessive Elements
Limiting the Number of Characters in a Jtextfield