Spring Framework

Home/Spring Framework

Spring @PropertySource to read property files

Introduction: The @PropertySource annotation in Spring provides a convenient and declarative mechanism for reading properties files. Properties files contain key-value pairs, e.g. app.log.level = DEBUG. In this article, you will learn to read a value from the property file using @PropertySource and access the specific values using @Value annotation and Environment field. If you are new to Spring, make sure [...]

By |2020-04-06T16:37:33+00:00April 6th, 2020|Categories: Spring Framework|Tags: , , |

IoC Container, Bean Factory vs Application Context in Spring

In this article, you will learn the differences between IoC Container, Application Context and the Bean Factory in Spring Framework. The Spring IoC container is the core of the Spring Framework. It creates the class instances, wires them together, configures them, and manages their complete life cycle from creation till destruction. The Spring container uses dependency injection (DI) to manage [...]

By |2020-04-05T13:17:40+00:00April 5th, 2020|Categories: Spring Framework|Tags: , |

Classpath Scanning using @ComponentScan and Filters

Introduction: A Classpath scanning basically means, detecting the classes that need to be managed by the Spring under a specified package. You need to make use of the spring @ComponentScan annotation with the @Configuration for classpath scanning. This annotation allows you to specify a base package and also a filter if needed to fine control the package scanning. We will [...]

By |2020-04-04T17:44:03+00:00April 4th, 2020|Categories: Spring Framework|Tags: |

Managed beans using @Component, @Repository, @Service

Introduction: In this tutorial, you will learn the different Spring stereotype annotations (@Component, @Repository and @Service) to declare any class as a Spring-managed Bean. Spring MVC also has several other annotations like @Controller and @RestController. The classes that are managed as beans in Spring are known as Managed Components. There are basically few stereotype annotations in spring that declare classes [...]

By |2020-04-03T18:42:22+00:00April 3rd, 2020|Categories: Java™, Spring Framework|Tags: |

RabbitMQ with Spring AMQP and Spring Boot

In this tutorial, we will explore the use of Spring AMQP to communicate with the RabbitMQ messaging middleware. All the previous article code examples are based on the RabbitMQ-Java-Client library. Spring AMQP also makes use of the same library, however, it provides a practical oriented approach to communicate with RabbitMQ. If you are already familiar with Spring stack, then you [...]

By |2020-03-31T06:45:00+00:00March 31st, 2020|Categories: RabbitMQ, Spring Framework|Tags: , |

Fine-tune auto wiring using @Primary and @Qualifier

Introduction Autowiring by type can lead to ambiguity when we have multiple beans of the same base class type. Because there are multiple beans of the same type, it is important to have control over the bean selection process. Spring provides @Primary annotation which declares a specific bean as primary, which means primary bean will be given higher preferences when [...]

By |2020-02-26T17:52:42+00:00February 26th, 2020|Categories: Java™, Spring Framework|Tags: |

Dependency Injection: @Autowired, @Resource and @Inject

In Spring Framework, you can basically use any of the three annotations for Dependency Injection, namely @Autowired, @Resource and @Inject. The @Autowired annotation belongs to the core-spring, however, the other two belongs to the Java extension package @javax.annotation.Resource and @javax.inject.Inject. We will look into the use of each of these annotations with a practical use case, to help you choose [...]

By |2020-02-24T17:06:37+00:00February 23rd, 2020|Categories: Java™, Spring Framework|Tags: |

Spring BeanPostProcessor to customize beans

Spring BeanPostProcessor beans are a special kind of beans that get created before any other beans and Spring allows you to assign customize callbacks to it. Spring provides the BeanPostProcessor interface, you can implement its methods to provide your own instantiation logic and dependency resolution logic. NOTE - the following before working with BeanPostProcessor. BeanPostProcessor methods are executed after the [...]

By |2020-02-16T02:04:24+00:00February 15th, 2020|Categories: Java™, Spring Framework|Tags: , |

Spring bean definition Inheritance

In Spring Framework, bean definition inheritance (bean configuration inheritance) is a valuable time-saving feature we must learn. As you know, a bean definition is nothing but the configuration for the Spring IoC container to create our bean as per the details. Refer to the article Inversion of Control and Dependency Injection in Spring, if you need to understand the basics [...]

By |2020-02-13T12:49:14+00:00February 13th, 2020|Categories: Java™, Spring Framework|Tags: |

Mapping and Injecting Collections in Spring

Spring Framework supports the injection of the Java Collection types List, Set, Map and Properties. You can use XML as well as annotations based configurations. We will learn Constructor, Setter, and Field injections for the collections using annotations based configurations in this article. The complete code example is available in the GitHub code repository. I recommend understanding the basics of [...]

By |2020-01-22T08:00:43+00:00January 22nd, 2020|Categories: Java™, Spring Framework|Tags: , |