1、直接注入
@autowired
private XXXService xxxService;
2、也可以注入属性的set方法上
@RestController
public class DemoController {
private DemoService demoService;
@Autowired
public void setDemoService(DemoService demoService) {
this.demoService = demoService;
}
@RequestMapping("/demo")
public String demo(){
demoService.demo();
return "demo ok";
}
}
而且使用下面的方法,不会有提示信息
原文:https://www.cnblogs.com/binstudy/p/15030259.html