Dependency Injection & IoC — Four Techniques
A hands-on study of Inversion of Control in Java: the same DAO/business layering wired four ways — manual setter injection, reflection-based dynamic loading from a config file, Spring XML container config, and Spring annotation scanning (@Component/@Autowired).
Implement one interface-driven app four ways: static, dynamic reflection, Spring XML, Spring annotations
A foundational walkthrough of Inversion of Control & Dependency Injection — "depend on interfaces, not implementations" — building the same app four different ways.
Structure
java-ioc-1/ (Maven + Spring 6)
├── dao/ IDao + implementations
├── metier/ IMetier + implementations
└── presentation/ 4 injection demos
enset_ioc/ (pure-Java starting point)
Four injection techniques
| Demo | Method | How |
|---|---|---|
| Presentation | Static | manual new + setter injection |
| Presentation2 | Dynamic | reflection-based class loading from config.txt |
| Presentationxml | Spring XML | container wiring via applicationContext.xml |
| PresentationAnnotation | Spring Annotations | @Component + @Autowired component scanning |
Why it matters
The IDao (data-access contract) and IMetier (business contract) are coupled only through interfaces, so the container — not the code — decides which implementation is injected. This is the principle every later Spring project in this collection relies on.