Implementing instance factory method using Spring annotations

In this post under Spring Core, I will show how to implement instance factory method using Spring annotations instead of using xml approach. For our example, lets create “Calculator” class with below structure, whose bean we have to create using instance factory method Calculator package core.package53; public class Calculator { public void calculate() { System.out.println(“Calculating….”);…… Continue reading Implementing instance factory method using Spring annotations

Implementing static factory method using Spring annotations

In this post under Spring Core, I will show how to implement static factory method using Spring annotations instead of using xml approach. For our example, lets create “Calculator” class with below structure, whose bean we have to create using factory method Calculator package core.package52; public class Calculator { public void calculate() { System.out.println(“Calculating….”); }…… Continue reading Implementing static factory method using Spring annotations

Using @Lookup on method with its local and instance arguments

In my previous post under Spring Core, I have explained the use of “@Lookup” annotation and how to use it with or without its arguments. In this post, I will show with example, how we can use “@Lookup” (with or without its argument) with a method that takes a local variable and instance variable as…… Continue reading Using @Lookup on method with its local and instance arguments

BeanPostProcessor example

In this post under Spring Core, I will explain with example the purpose and how to use “BeanPostProcessor” interface. In Spring framework when a bean is created, It is first constructed by calling its constructor, then dependencies are injected and initialization logic if any is executed. It is during this initialization phase that we can…… Continue reading BeanPostProcessor example

Using @Lazy annotation with @Autowired annotation example

In this post under Spring Core, I will show with example how to use “@Lazy” annotation with “@Autowired” annotation and how it change the behavior of Spring framework. In previous post, I showed with example how to use “@Lazy” annotation with “@Component” and “@Bean” annotation and how they change the behavior of Spring framework. Just…… Continue reading Using @Lazy annotation with @Autowired annotation example

Using @Lazy annotation with @Bean and @Component example

In this post under Spring Core, I will explain with example the purpose of “@Lazy” annotation and how it reacts when used with “@Bean” and “@Component” annotation. In Spring, we can use “@Lazy” annotation for two purposes1) to instruct Spring framework to lazily create a singleton bean2) to instruct Spring framework to lazily inject a…… Continue reading Using @Lazy annotation with @Bean and @Component example

Using Generics as Autowiring Qualifiers

In this post under Spring Core, I will show with example how Spring uses generics information when autowiring generic beans annotated with “@Qualifier” annotation. For our example I will create an generic interface “Store” as shown below Store interface package core.package47; public interface Store<T> { public void display(); } This generic interface has two implementations…… Continue reading Using Generics as Autowiring Qualifiers

Custom Qualifier with @Bean annotation

Custom Qualifier with @Bean annotation In this post under Spring Core, I will show with example how to create a custom qualifier and use it with “@Bean” annotation. For our example, I will create a “@DaoGenre” custom qualifier as shown below Custom Qualifer package core.package46; import org.springframework.beans.factory.annotation.Qualifier; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;…… Continue reading Custom Qualifier with @Bean annotation

Custom Qualifier with @Component annotation

In this post under Spring Core, I will show with example how to create a custom qualifier and use it with “@Component” annotation. For our example, I will create a “@MovieGenre” custom qualifier as shown below Custom Qualifier package core.package45; import org.springframework.beans.factory.annotation.Qualifier; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Qualifier @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME)…… Continue reading Custom Qualifier with @Component annotation

Autowiring by Name (Using @Qualifier with @Component annotation)

In previous post under Spring Core, I showed with example how to use “@Qualifier” annotation with “@Bean” annotation. In this post under Spring Core, I will show with example how to use “@Qualifier” annotation with “@Component” annotation. For our example I will create an interface named “IMovie” as shown below IMovie package core.package44; public interface…… Continue reading Autowiring by Name (Using @Qualifier with @Component annotation)