field injection is not recommended
-
使用@Autowired依赖注入时,IDEA弹出如上警告,可忽略
-
科普:常见的依赖注入方式有以下三种
-
@Autowired
@Autowired private InventoryMapper inventoryMapper;
-
构造器注入
private final InventoryMapper inventoryMapper; public InventoryController(InventoryMapper inventoryMapper) { this.inventoryMapper = inventoryMapper; }
-
Setter注入
private InventoryMapper inventoryMapper; public void setInventoryMapper(InventoryMapper inventoryMapper) { this.inventoryMapper = inventoryMapper; }
-