因为这种注入方式存在缺陷,springboot不建议使用这种方式。可以采用构造方法的方式来注入
修改前:
@RestController public class UserController { @Autowired UserMapper userMapper; @RequestMapping("/select") public String select(){ return userMapper.selectAll().toString(); } }
修改后:
@RestController public class UserController { final UserMapper userMapper; public UserController(UserMapper userMapper){ this.userMapper = userMapper; } @RequestMapping("/select") public String select(){ return userMapper.selectAll().toString(); } }