Spring – Init Method and Destroy Method

Concept Overview Sometimes, after Spring beans are created, they need to perform some additional initialization operations so that they can carry out their responsibilities. e.g. When an ATM (Automated Teller Machine) system is started, it needs to connect to its bank’s network. Similary, sometimes Spring beans need to peform some cleanup operations before it gets … Read more

Spring Method Injection

Concept Overview In typical software development, classes depend on each other to achieve a desired functionality. e.g. An Automatic Ticket Vending Machine class depends on Ticket class to achieve the functionality of generating tickets. The dependencies need to be ‘resolved’ before the desired functionality is can be achieved. When dependency resolution is not performed by … Read more

Spring Bean Scopes

The Primary Spring bean scopes are Singleton and Prototype. In Singleton scope, the spring container instantiates only one instance of a bean per container. In Prototype scope, the container returns a new instance of a bean whenever we ask the container for that bean. Other bean scopes applicable only to web environments are request, session, … Read more

Spring Inner Bean Injection

A bean defined within the context of another bean is called a spring inner bean. It is similar to the concept of inner classes in java. e.g. In an ATM (Automated Teller Machine) system, it is possible for the Printer bean to be defined as an inner bean of ATM class. Github – Source Code … Read more

Spring Setter Injection

What is Setter Injection in Spring Setter Injection in Spring is a type of dependency injection in which the framework injects the dependent objects into the client using a setter method. The container first calls the no argument constructor and then calls the setters. The setter based injection can work even If some dependencies have … Read more

Spring Constructor Injection

Spring Constructor Injection is a form of Dependency Injection where the objects are injected into the client using the client constructor. Example of Spring Constructor injection Github – Source Code for this example In typical software development, classes collaborate with each other to achieve the desired functionality. e.g. In an ATM (Automated Teller Machine) system, … Read more

Dependency Injection in Spring, Introduction and types

Definition of Dependency Injection in Spring Dependency Injection is a software engineering pattern in which a dependent object is passed on to the client by an external agency such as the Spring container. Dependency Injection is one way to achieve Inversion of Control since the control of creating the Objects is not with the client … Read more