This Maven project shows DI (dependency injection), without using
any DI framework.
So if you try to run Main.main
, you get
NullPointerException
s for each Controller object, as no
implementation was injected.
Instead, we will manually inject the object references by using the
JUnit framework.
So instead of running “java com.wpollock.dimanual.Main
”,
you would run the JUnit test.
Three different DI methods are shown: property injection (which usually uses reflection but not in this example), setter injection, and constructor injection. Constructor injection is considered the best practice.