Spring boot 注入失败

原文链接: https://my.oschina.net/u/1011659/blog/3049803

spring boot注入失败的场景主要有

Application类位置异常

  1. 待注入的类位于Application类所在包的外层;
  2. @ComponentScan扫描的位置没有包括待注入的bean的包

方法作用域问题

该问题我们在Controller层出现过, 具体代码如下

@RestController
@RequestMapping("/mis")
public class XXXrMisController {

    @Autowired
    private MonitorMisService monitorMisService;

    @GetMapping("/Info")
    private CommonResponse liveUrlInfo() {
        CommonResponse commonResponse = CommonResponse.success();
        return commonResponse.setResult(monitorMisService.Info(sn, channel));
    }
}

问题出现在liveURLInfo方法的作用域,使用private方法,相应的对MonitorMisService 的依赖就不能注入,改为public就可以了。具体原因待查

转载于:https://my.oschina.net/u/1011659/blog/3049803

你可能感兴趣的:(Spring boot 注入失败)