This project is a pure Spring Framework (Spring Core) learning project designed to demonstrate the fundamental concepts behind Spring's Inversion of Control (IoC) container, Dependency Injection (DI), bean management, autowiring, and component scanning.
Unlike Spring Boot, this project uses the core Spring Framework directly, helping build a deeper understanding of how Spring manages objects, dependencies, and application configuration internally.
This project serves as a foundational step toward mastering Spring Boot and enterprise backend development.
The primary goal of this project is to learn and demonstrate:
- Inversion of Control (IoC)
- Dependency Injection (DI)
- Tight vs Loose Coupling
- Bean configuration using XML
- Constructor Injection
- Setter Injection
- Autowiring (byName, byType, constructor)
- Annotation-based configuration
- Component Scanning
- Spring IoC Container behavior
- ApplicationContext usage
- Java 23 (or compatible version)
- Spring Core
- Spring Context
- Maven
Dependencies used:
- spring-core
- spring-context
Spring_Project
โ
โโโ src
โ โโโ main
โ โ โโโ java
โ โ โ
โ โ โโโ car.example
โ โ โ โโโ bean
โ โ โ โ โโโ App.java
โ โ โ โ โโโ MyBean.java
โ โ โ โ
โ โ โ โโโ constructor.injection
โ โ โ โ โโโ App.java
โ โ โ โ โโโ Car.java
โ โ โ โ โโโ Specification.java
โ โ โ โ
โ โ โ โโโ setter.injection
โ โ โ โโโ App.java
โ โ โ โโโ Car.java
โ โ โ โโโ Specification.java
โ โ โ
โ โ โโโ com.example
โ โ โ โโโ autowire
โ โ โ โโโ constructor
โ โ โ โ โโโ App.java
โ โ โ โ โโโ Car.java
โ โ โ โ โโโ Specification.java
โ โ โ โ
โ โ โ โโโ name
โ โ โ โ โโโ App.java
โ โ โ โ โโโ Car.java
โ โ โ โ โโโ Specification.java
โ โ โ โ
โ โ โ โโโ type
โ โ โ โโโ App.java
โ โ โ โโโ Car.java
โ โ โ โโโ Specification.java
โ โ โ
โ โ โโโ autowired.annotations
โ โ โ โโโ App.java
โ โ โ โโโ AppConfig.java
โ โ โ โโโ Employee.java
โ โ โ โโโ Manager.java
โ โ โ
โ โ โโโ componentscan.annotation
โ โ โ โโโ App.java
โ โ โ โโโ Employee.java
โ โ โ
โ โ โโโ ioc.coupling
โ โ โ โโโ IOCExample.java
โ โ โ โโโ NewDatabaseProvider.java
โ โ โ โโโ UserDatabaseProvider.java
โ โ โ โโโ UserDataProvider.java
โ โ โ โโโ UserManager.java
โ โ โ โโโ WebServiceDataProvider.java
โ โ โ
โ โ โโโ loose.coupling
โ โ โ โโโ LooseCouplingExample.java
โ โ โ โโโ NewDatabaseProvider.java
โ โ โ โโโ UserDatabaseProvider.java
โ โ โ โโโ UserDataProvider.java
โ โ โ โโโ UserManager.java
โ โ โ
โ โ โโโ tight.coupling
โ โ โ โโโ TightCouplingExample.java
โ โ โ โโโ UserDatabase.java
โ โ โ โโโ UserManager.java
โ โ โ
โ โ โโโ resources
โ โ โโโ applicationBeanContext.xml
โ โ โโโ applicationConstructorInjection.xml
โ โ โโโ applicationIoCLooseCouplingExample.xml
โ โ โโโ applicationSetterInjection.xml
โ โ โโโ autowireByConstructor.xml
โ โ โโโ autowireByName.xml
โ โ โโโ autowireByType.xml
โ โ โโโ componentScanDemo.xml
โ โ
โ โโโ test
โ
โโโ pom.xml
โโโ .gitattributes
โโโ README.md
In traditional programming, objects create their dependencies.
In Spring, the container creates and manages objects.
Example (Without IoC):
UserManager manager = new UserManager();
Example (With IoC):
Spring creates the UserManager object and injects dependencies automatically.
Benefits:
- Reduces coupling
- Improves flexibility
- Improves maintainability
Dependency Injection means providing dependencies to objects instead of letting them create dependencies themselves.
Spring supports multiple types:
Dependencies are injected through the constructor.
Example:
public Car(Specification spec) {
this.spec = spec;
}
Configured in XML:
<constructor-arg ref="specificationBean"/>
Benefits:
- Ensures required dependencies are available
- Makes objects immutable
Dependencies are injected using setter methods.
Example:
public void setSpecification(Specification spec) {
this.spec = spec;
}
Configured in XML:
<property name="specification" ref="specificationBean"/>
Benefits:
- Allows optional dependencies
- More flexible
Spring automatically injects dependencies.
Types demonstrated:
Matches bean name with property name.
autowire="byName"
Matches bean type with property type.
autowire="byType"
Matches constructor parameter type.
autowire="constructor"
Uses annotations like:
@Autowired
@Component
@Configuration
Spring automatically resolves dependencies.
Benefits:
- Cleaner code
- Less XML configuration
Spring automatically detects classes annotated with:
@Component
@Service
@Repository
Configured using:
<context:component-scan base-package="com.example"/>
Classes depend directly on specific implementations.
Example:
UserDatabase db = new UserDatabase();
Problems:
- Hard to change implementation
- Not flexible
Classes depend on interfaces instead of implementations.
Example:
UserDataProvider provider;
Spring injects appropriate implementation.
Benefits:
- Flexible
- Easy to extend
- Easier testing
The container:
- Creates objects (beans)
- Injects dependencies
- Manages lifecycle
Example:
ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");
- Java installed
- Maven installed
- IDE (IntelliJ recommended)
mvn clean install
Run any App.java file from IDE.
Example:
car.example.constructor.injection.App
or
ioc.coupling.IOCExample
After completing this project, you will understand:
- How Spring IoC container works
- How Spring manages objects
- How Dependency Injection works internally
- Difference between tight coupling and loose coupling
- XML vs Annotation configuration
- Foundation required for Spring Boot
- Add Spring Boot version of project
- Add Spring MVC
- Add database integration
- Add REST APIs
Aaryaman Jhatakia
GitHub: https://github.com/Aaryamanjhatakia