You need to use a setter because annotations are not detected unless spring is told so through either
or
. Setter is detected because you specified autowire="byType"
.
You may find this question and answer helpful as well: When to use autowiring in Spring