Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relationship between Weld and HK2

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

like image 545
user2465039 Avatar asked Aug 13 '14 15:08

user2465039


1 Answers

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.

like image 122
Jan Galinski Avatar answered Oct 21 '22 08:10

Jan Galinski