Spring vs. Jakarta EE: Injecting Dependencies

The article “Spring vs. Jakarta EE: Defining Injectable Beans” addressed the “first half” of Dependency Injection in Spring and Jakarta EE: the definition of beans that shall be injected. The current article discusses the details of how these beans can be injected. This forms the second part of the dependency injection process, which can be further broken down into the following aspects:

  • Annotations: Which annotations can be used for injection?
  • Disambiguation: How to perform disambiguation if there are multiple candidates for injection?
  • Optional and Multiple Injection: How to gracefully deal with the absence of injectable beans, and how to inject several beans of the same type?
  • Programmatic Injection: How to inject dependencies without annotations?

For the impatient, here is a summary table for these topics, with more details following below:                                                                         

Spring vs. Jakarta EE: Defining Injectable Beans

Dependency Injection is one of the core features in the heart of modern application development frameworks. In a nutshell, the process of dependency injection is composed of

  1. the definition of injectable beans 
  2. the injection of beans (dependencies) into those places where they are required

This blog post compares the mechanisms available in the Spring Framework and Jakarta EE for the first part of this process, which can be further broken down into the following aspects: