Spring @Autowired for setter methods vs non-setter methods

前端 未结 3 1735
北海茫月
北海茫月 2021-02-09 18:47

According to @Autowired javadoc:

Marks a constructor, field, setter method or config method as to be autowired by Spring\'s dependency injection facili

3条回答
  •  渐次进展
    2021-02-09 19:34

    @Autowired annotation can be used with constructor, setter method or just any other method. Whenever Spring finds @Autowired annotation it will try to find beans matching to method parameters and will invoke that method. If multiple methods (setter or non-setter) have @Autowired annotation, all will be invoked by Spring after bean instantiation.

提交回复
热议问题