Spring Injection Order
First of all don't mix and match injection for your fields
If you are going to let Spring do your dependency injections for you, just stick to one method. Constructor, setter, or field injections.
However, if you're curious on the order of the evaluation here it is
- It will call the constructor and inject the necessary dependency, since a constructor is needed before anything happens
- It will then inject fields annotated with @Autowired, which are the field injections
- Finally it will call methods annotated with @Autowired, which are the setter injections
So in conclusion, setter injection takes precedence over all the other methods. Again don't mix and match the type of injections that you are using, it is bad practice and is confusing.
No Comments