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:

Creating Camel 3 CDI Microservices

As many people already know, Apache Camel is an open-source project that makes easy implement integration projects, in this post I want to go through some libraries that allow creating microservices within a camel ecosystem (Pure Apache Camel 3 microservices).

In order to create microservices with camel we can combine some camel modules such:

Contexts and Dependency Injection (CDI): Eager Extensions

CDI does not provide eager extensions out of the box. Even though there is @ApplicationScoped, which is intended to work in a similar way to eager instantiation, it does not behave in the specified fashion. 

I am going to describe how to use CDI extensions to get eagerly instantiated beans following the CDI lifecycle — inside the container. I have used this in Wildfly 8.0.