This Maven project shows DI (dependency injection), without using
any DI framework.
So if you try to run
Main.main, you get
NullPointerExceptions for each Controller object, as no
implementation was injected.
Instead, we will manually inject the object references by using the
So instead of running “
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.