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: