Section 1: Introduction to Spring Core

Spring, being a vast framework, is organized into several modules to maintain lightweight architecture. Notable modules include:

  1. Spring Core
  2. Spring AOP
  3. Spring JDBC
  4. Spring Transaction
  5. Spring ORM
  6. Spring MVC

All Spring modules are independent except for the foundational module, Spring Core, which serves as the base for the entire framework.

Spring Core

Spring Core focuses on dependency management, allowing Spring to effectively handle dependencies when arbitrary classes are provided to it.

What is a Dependency?

In a project or application, various classes with different functionalities coexist. Each class may require some functionality from other classes, leading to dependencies. For example:

class Engine {
    public void start() {
        System.out.println("Engine started");
    }
}

class Car {
    public void move() {
        // For moving, the start() method of the Engine class is required
    }
}

In this example, the Car class is dependent on the Engine class. Traditionally, dependency management can be handled through inheritance or by creating an object of the dependent class.

Traditional Dependency Management

By Inheritance:

class Engine {
    public void start() {
        System.out.println("Engine started");
    }
}

class Car extends Engine {
    public void move() {
        start(); // Calling the superclass start method
    }
}

By Creating an Object:

class Engine {
    public void start() {
        System.out.println("Engine started");
    }
}

class Car {
    Engine eng = new Engine();

    public void move() {
        eng.start();
    }
}