All Projects
Backend

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).

4
Injection techniques
Spring 6
Framework
IDao + IMetier
Contracts
XML + annotations
Wiring
Approach

Implement one interface-driven app four ways: static, dynamic reflection, Spring XML, Spring annotations

Tech Stack
Java 17Spring 6.1MavenReflection API
Keywords
SpringIoCDependency InjectionReflectionXML ConfigAnnotationsJava
Deep Dive

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

DemoMethodHow
PresentationStaticmanual new + setter injection
Presentation2Dynamicreflection-based class loading from config.txt
PresentationxmlSpring XMLcontainer wiring via applicationContext.xml
PresentationAnnotationSpring 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.