Spring Caching Simple (@Cacheable) Example Class Level Part 1

In this post under Spring Caching, I will show with example how to enable and use caching at class level in Spring application. For our example, we will use “Calculator” class which has “calculate” method which will perform heavy calculation. It will perform summation from 1 to 1000000. We cannot perform the calculation every time,…… Continue reading Spring Caching Simple (@Cacheable) Example Class Level Part 1

Spring Caching Simple (@Cacheable) Example Method Level

In this post under Spring Caching, I will show with example how to enable and use caching in Spring application. For our example, we will use “Calculator” class which has “calculate” method which will perform heavy calculation. It will perform summation from 1 to 1000000. We cannot perform the calculation every time, so we have…… Continue reading Spring Caching Simple (@Cacheable) Example Method Level

Ordering multiple BeanPostProcessor implementations example

In this post under Spring Core, I will show with example how to order multiple “BeanPostProcessor” interface implementations. To order multiple “BeanPostProcessor” implementations, each implementations much implement “Ordered” interface and provide order number in the interface “getOrder” method. Note: Ordering of “BeanPostProcessor” implementations only work with “@Component” annotation and not with “@Bean” annotation. For our…… Continue reading Ordering multiple BeanPostProcessor implementations example

BeanFactoryPostProcessor example

In this post under Spring Core, I will explain with example the purpose of “BeanFactoryPostProcessor” Spring class. We define our Spring beans and give it to Spring container to create instances of those beans. Spring container reads the bean definitions and create instances of beans. What if we want to change the definition of those…… Continue reading BeanFactoryPostProcessor example

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