Spring Tutorial in One Shot

Java Developer Guide
1 min readJul 2, 2024

--

Spring is a Dependency Injection framework to make Java applications loosely coupled.

Dependency Injection: It is a design pattern.

Spring can create and inject an object of a class into another class.

Creating an object of a class and inserting it into another class is called Inversion of control.

Java applications have multiple layers:

  1. UI Layer: Java classes (Product Controller).
  2. Business/Service layer: Business logic (Product Service).
  3. Data access layer: Product Dao.
  4. Database.

The problem with creating objects using “new” keyword.

public class ClassA{
...
...
}

Now suppose we create an object of ClassA into ClassB using “new” keywork.

public class ClassB{
...
...
ClassA obj1 = new ClassA();
}

Now the problem here is that if we do some changes product DAO then we need to go into productService and recompile our application. This method can be used in small applications. But in enterprise-level applications it is not recommended.

Spring Modules:

Spring-Core contains 4 modules…

  1. Core
  2. beans
  3. Context
  4. spEL (Spring Expression language)…

Spring IoC Container: does three jobs…

  1. Create the object.
  2. Hold them in memory.
  3. Inject them into another object as required.

We need to tell two things to the container…

  1. Beans (Java POJO Classes).

2. XML Configuration (It will tell that which object depends on which object).

So container will inject the objects according to the configuration file information.

ApplicationContext: It is an interface that represent IOC Container. It extends the bean factory.

--

--