https://blog.csdn.net/Hello_World_QWP/article/details/116119502
构造器的依赖注入
Setter的依赖注入
字段变量的依赖注入
还有其它不常用的注入方式:静态工厂方法注入、动态工厂方法注入
#构造器的依赖注入
private final InventoryMapper inventoryMapper;
public InventoryController(InventoryMapper inventoryMapper) {
this.inventoryMapper = inventoryMapper;
}
Setter注入:
private InventoryMapper inventoryMapper;
public void setInventoryMapper(InventoryMapper inventoryMapper) {
this.inventoryMapper = inventoryMapper;
}
字段变量注入:
@Autowired
private InventoryMapper inventoryMapper;
@Autowired:表示自动注入,自动从spring的上下文找到合适的bean来注入