An Introduction to Spring Framework

Sneha Sethi
3 min readFeb 9, 2021

--

Spring framework is an open-source java platform and most popular for building Java applications. The spring framework was designed by Rod Johnson in 2003. Spring framework is used for developing reliable, secure, and high-quality applications. It is a lightweight framework that provides well-defined infrastructure support and extensions for developing applications in Java. But why spring is so popular and used by industry professionals? Or what is this spring? To find out the answers to these questions, let’s go deeper in the spring.

To understand spring let’s first understand two important aspects of the spring framework.

  1. Inversion of control(IoC)
  2. Dependency Injection(DI)
Basic Architecture of IoC

As shown in the above figure Inversion of Control implements different implementations, Dependency Injection is also one of them.

Inversion of Control:

In traditional programming, the flow of the business logic is determined by the objects that are bound to each other. With Inversion of control, control of the flow is given to the container to get an instance of the object, rather than creating it by yourself container will do that for you.

As shown in the above diagram container get the objects from metadata like XML and also uses the Java POJO class to produce a completely configured application System. The metadata can be in any form like XML, annotations, or java code.

Dependency Injection:

Dependency Injection is one of the type of IoC, in which dependencies are injected at runtime by using constructor injection and setter injection techniques.

As mentioned above there two techniques in spring by which dependencies are injected:

  1. Constructor Injection
  2. Setter Injection

Constructor Injection is achieved by invoking a constructor method in which field parameters are passed at the time of instantiation.

The code for the constructor injection method is given below:

package com.coach;

public class BaseBall implements Coach {

private FortuneService fortuneService;

public BaseBall(FortuneService thefortuneService) {

fortuneService = thefortuneService;

}

}

Setter Injection is achieved by invoking the setter method after defining a no-argument constructor to instantiate your bean.

The code for the setter injection method is given below:

package com.coach;

public class CricketCoach implements Coach {

private FortuneService fortuneService;

public CricketCoach{

}

public void setFortuneService(FortuneService fortuneService) {

this.fortuneService = fortuneService;

}

}

Applications of Spring framework:

Spring framework is lightweight, modular, fast-paced, uses POJO based as it is simple to write and use , easily testable, serverless, secure, and so on. With all these benefits, the spring framework is used for developing high-quality and highly secured applications. Spring frame work is extensively used for web applications, microservices, batch processing implementation, and so on. Spring also provides a spring cloud suite that contains many of the services you need to make your applications run in the cloud.

Conclusion:

In this article, we have studied about spring framework and its benefits and applications. We also have studied important aspects of the spring framework IoC and DI which gives us ideas about working and a basic understanding of the spring framework. Stay tuned for further articles on Spring and other technologies.

--

--