首页 > 其他 > 详细

@autowired使用

时间:2021-07-19 17:16:54      阅读:25      评论:0      收藏:0      [点我收藏+]

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


}
而且使用下面的方法,不会有提示信息

@autowired使用

原文:https://www.cnblogs.com/binstudy/p/15030259.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!