In this post under Spring Core, I will explain with example the purpose of “@Order” annotation. In one of my previous posts under Spring Core, I have explained how to autowire collections, array, and map. For the purpose of recap, lets assume we have a class “Dao” which we want to inject in class “Example22″…… Continue reading Spring @Order annotation
Author: sumanthprabhakar
Autowiring Optional beans
In this post under Spring Core, I will show with example how to use Java’s Optional class to declare a bean (to be injected) as optional. In one of my previous post under Spring Core, I showed you about “required” attribute in “@Autowired” annotation. For recap, “@Autowired” annotation has only one attribute named “required” whose…… Continue reading Autowiring Optional beans
Autowiring a map
In this post under Spring Core, I will show with example how to autowire a map. For this example I will use the below “Dao” class Dao class package package23; public class Dao { } Below is the main class that shows how to autowire a map Main class 1 package package23; 2 3 import…… Continue reading Autowiring a map
Autowiring a collection and array of beans
In this post under Spring Core, I will explain with example how to autowire a collection and array of beans. For our example I will use the below “Dao” class Dao class package package22; public class Dao { private String daoName; public Dao(String daoName) { this.daoName = daoName; } @Override public String toString() { return…… Continue reading Autowiring a collection and array of beans
CollectionUtils getCardinalityMap method
In this post under Apache Collections, I will explain with example, the purpose of CollectionUtils “getCardinalityMap” method. This method takes a collection as an argument and returns a map. A map where key is an element from the collection, and value will be the number of times the element is repeated in the collection. So…… Continue reading CollectionUtils getCardinalityMap method
CollectionUtils intersection method
In this post under Apache Collections, I will explain with example the purpose of CollectionUtils “intersection” method. The “intersection” method compares two collections and return a new list containing items that are common in both of them. Below is the complete main code for your reference. Main class 1 package defaultPackage; 2 3 import org.apache.commons.collections4.CollectionUtils;…… Continue reading CollectionUtils intersection method
“required” attribute of @Autowired annotation
In this post under Spring Core, I will explain with example the purpose of “required” attribute of “@Autowired” annotation. When we tell Spring framework to wire two beans say “Bean2” to “Bean1” as shown below package package20;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;@Componentpublic class Bean1 { @Autowired private Bean2 bean2; public Bean2 getBean2() { return bean2; } public void…… Continue reading “required” attribute of @Autowired annotation
CollectionUtils containsAny method
In this post under Apache Collections, I will explain with example the purpose of CollectionUtils “containsAny” method. This method is used to compare two collections. It returns true if both the collections has atleast one element in common or else false. Below is the main class for your reference Main class 1 package defaultPackage;2 3…… Continue reading CollectionUtils containsAny method
Example of @Autowired (setter injection approach 2)
In this post under Spring Core, I will show another approach of achieving setter injection using “@Autowired” annotation. In my previous posts, I showed with example how to achieve setter injection by applying “@Autowired” annotation at field level. In this post I will show how to achieve setter injection by applying “@Autowired” annotation directly on…… Continue reading Example of @Autowired (setter injection approach 2)
Example of @Autowired (constructor injection)
In this post under Spring Core, I will show with example, how to use “@Autowired” annotation for constructor injection. In previous post, I showed how to use “@Autowired” annotation for setter injection. We call an approach as setter injection, when Spring framework automatically inject dependency to an object by calling the setter method of the…… Continue reading Example of @Autowired (constructor injection)