@autowired使用

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";
}


}
而且使用下面的方法,不会有提示信息
posted @ 2021-07-19 15:09  neoQVQ  阅读(81)  评论(0)    收藏  举报