Spring @Autowired for setter methods vs non-setter methods

前端 未结 3 1734
北海茫月
北海茫月 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:16

    A config method is a factory-like method, which in this case would get the paramaters autowired:

    @Autowired
    public SomeObject initSomeObject(Object1 o1, Object2 o2, ...) {
    

    @Autowired merely ensures that Spring will (attempt to) provide the needed parameters.

提交回复
热议问题