What is the relationship between Weld and HK2
Asked Answered
S

1

16

This might be a silly question, but I am puzzled by it and I could not find any clear explanation anywhere.

HK2 is a dependency injection framework implementing JS330, the foundation of Glassfish V3 and V4. As far as I can see it is used by Jersey

Weld is the reference implementation for CDI which is again a dependency injection framework and can also be used in Glassfish?

So my questions are these

  • Are they different implementations of the same spec?
  • Are they implementations of different specs?
  • Under what circumstances shall I use one or the other?

I understand that the questions arise from my meagre understanding of the whole ecosystem of Java EE but any answers will be greatly appreciated

Spartan answered 13/8, 2014 at 15:56 Comment(0)
A
24

JSR330 deals with Dependency Injection. Implementations are for example Guice, HK2 and Spring. Weld does implement JSR330 but goes one step further by also implementing JSR299, specifying modules, interceptors, custom scopes, ... see this article for a short comparison.

Java EE combines several specs, not only injection but also persistence, security, web services, server faces, ... and thus requires application servers like glassfish or jboss, while (C)DI can easily used with standard web containers (jetty, tomcat) or even standalone applications.

Andonis answered 13/8, 2014 at 20:1 Comment(2)
Thanks for the answer and the link. At least I see that I was not the only one, baffled by itSpartan
As this vote is getting upvoted ... care to accept it?Andonis

© 2022 - 2024 — McMap. All rights reserved.