Always use constructor based dependency injection in your beans. Always use assertions for mandatory dependencies
@Autowired注解 总是在您的bean中使用构造函数建立依赖注入。总是使用断言强制依赖
原始写法
@Autowired
private UserService userService;建议写法
private final UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}原因:Java变量的初始化顺序为:静态变量或静态语句块–>实例变量或初始化语句块–>构造方法–>@Autowired