This project demonstrates the Annotation-Based Configuration method using Spring's Component Scanning capabilities. This is the most modern and common way to handle Dependency Injection in Spring Boot.
- Auto-Detection: Using
@ComponentScanto find beans automatically. - Stereotype Annotations: Marking classes with
@Componentto register them in the IoC container. - Auto-wiring: Using
@Autowiredto inject dependencies without manual setters or constructors. - Ambiguity Handling:
@Primary: Defines a default bean implementation.@Qualifier: Allows specific selection between multiple implementations (JiovsAirtel).
This repo represents the 3rd stage of Spring learning:
- XML-Based (Manual)
- Java-Based (Semi-Manual)
- Component Scanning (Fully Automated) - Now are here
Spring scans the package org.spring.dependencyinjection.automatedcomponent.scanmethod.
- It finds
JioandAirteland creates beans namedjioBeanandairtelBean. - It finds the
Mobileclass and sees it is also a@Component. - It "wires" the
Simdependency intoMobileusing the ID provided in@Qualifier.
Jio Calling
Jio Data
Here is why your output will specifically show "Jio":
| Feature | What it does | Your Code |
|---|---|---|
@Primary |
The "Default" choice. | Set on Airtel. |
@Qualifier |
The "Specific" choice. | Set on Mobile (points to Jio). |
| Winner | Qualifier always wins. | Jio is printed. |