Spring, being a vast framework, is organized into several modules to maintain lightweight architecture. Notable modules include:
All Spring modules are independent except for the foundational module, Spring Core, which serves as the base for the entire framework.
Spring Core focuses on dependency management, allowing Spring to effectively handle dependencies when arbitrary classes are provided to it.
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.
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();
}
}