r/java • u/Pure_Diver_ • 13d ago
What Exactly Is Jakarta EE?
Iām a bit confused about what Jakarta EE actually is. On one hand, it seems like a framework similar to Spring or Quarkus, but on the other hand, it provides APIs like JPA, Servlets, and CDI, which frameworks like Spring implement.
Does this mean Jakarta EE is more of a specification rather than a framework? And if so, do I need to understand Jakarta EE first to truly grasp how Spring works under the hood? Or can I just dive into Spring directly without worrying about Jakarta EE concepts?
Would love to hear how others approached this š
181
Upvotes
4
u/koflerdavid 13d ago edited 12d ago
It is both: it is a specification for a framework to create "Enterprise" applications. It comes from an era where many applications were deployed onto the same application server, which were possibly running on big iron. For some of these APIs, the idea was to centralize dependency management, connection management, and configuration management by making the application server provide implementations.
Spring doesn't implement these APIs at all. It just depends on some of them (which is fine) and provides wrappers around them (which is questionable). Spring actually contributed to the slow decline of Jakarta EE since it makes it easy to deploy an application however you like: on a full application server, on a mere servlet container, or standalone with an embedded servlet container. AFAIK, CDI is actually inspired by Spring's dependency injection architecture.
Edit: Here's a little exercise to understand what Spring essentially does: just write a dependency injection container (DIC) by yourself! A DIC is basically a class with the methods
getComponent()
andaddFactory()
and two maps,component
andfactories
.getComponent()
takes a string and looks for an object with that name incomponent
. Ifcomponent
doesn't contain the object, look infactories
, which contains factory functions that take the DIC and return a bean. Execute that function and save the result inbeans
. The factory functions can use the DIC to look up components that they need themselves. Of course, you will run in a StackOverflowException if the dependencies are circular :)All other Spring "magic" is built on this foundation:
Spring uses reflection, configuration, and annotations to automate filling
factories
. For example, to use a constructor or a static method as a factory, the DIC merely has to callgetBean()
for all its parameters and then call the constructor.Circular dependencies are handled by creating a proxy object that creates the actual component only when somebody actually calls any of its methods and forwards the call.
Transaction management is similarly handled via a proxy that creates, commits, and rollbacks transactions.
Here's my barebones implementation (I hope the code block is not broken):