Using @Autowired in Abstract Classes 1. Introduction In this quick tutorial, we’ll explain how to use the @Autowired annotation in abstract classes. We’ll apply @Autowired to an abstract class, and focus on the important points which we should take into account. 2. Setter Injection We can use @Autowired on a setter… Continue Reading spring-autowired-abstract-class

Spring Core Annotations 1. Overview We can leverage the capabilities of Spring DI engine using the annotations in the org.springframework.beans.factory.annotation and org.springframework.context.annotation packages. We often call these “Spring core annotations” and we’ll review them in this tutorial. 2. DI-Related Annotations ==== 2.1. @Autowired We can use the @Autowired to mark a dependency… Continue Reading spring-core-annotations

XML-Based Injection in Spring 1. Introduction In this basic tutorial, we’ll learn how to do simple XML-based bean configuration with the Spring Framework. 2. Overview Let’s start by adding Spring’s library dependency in the pom.xml: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.1.4.RELEASE</version> </dependency> The latest version of the Spring dependency can be found… Continue Reading spring-xml-injection

Spring – Injecting Collections 1. Introduction In this tutorial, we’re going to show how to inject Java collections using the Spring framework. Simply put, we’ll demonstrate examples with the List, Map, Set collection interfaces. 2. List with @Autowired Let’s create an example bean: public class CollectionsBean { @Autowired private List<String> nameList;… Continue Reading spring-injecting-collections

Constructor Injection in Spring with Lombok 1. Introduction Lombok is an extremely useful library overcoming boilerplate code. If you are not familiar with it yet, I highly recommend taking a look at the previous tutorial – Introduction to Project Lombok. In this article, we’ll demonstrate its usability when combined with… Continue Reading spring-injection-lombok