springBoot启动报错问题汇总
springBoot启动报错问题千奇百怪,今天我们分享一下
一、启动时找不到配置文件
1、核心错误日志
target/classes/application.yml' (classpath:/application.yml)...MalformedInputException
2、原因分析
可能改目录没有这个配置文件,或者有配置文件,但是此配置文件字符集编码有问题,或者有空格等导致服务不能识别。
检查特殊字符:
# 在项目目录运行
cat -v src/main/resources/application.yml# Windows 使用 PowerShell
Get-Content src\main\resources\application.yml -Encoding Byte | Format-Hex
在线验证并返回正确的内容:
-
在线验证:YAMLlint - The YAML Validator
-
本地验证:
# 安装 yamllint pip install yamllint# 验证文件 yamllint src/main/resources/application.yml
二、依赖注入报错
1、报错日志
sys.dao.SysUserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:723)at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130),s
2、原因分析
1)可能没有添加依赖注入的相关注解,比如:
@Mapper或者@MapperScan({"com.modules.s.dao", "com.modules.p.dao"})或者@Autowired
2)以前成功启动,自从升级boot版本之后启动报错,很可能是依赖注入的问题,因为低版本boot支持依赖注入高版本boot不在支持依赖注入导致启动报错,解决方案可以是业务代码去除依赖注入或者 在相关的依赖注入上 添加一个注解:@Lazy
@Lazy@Autowiredprivate SysUserService sysUserService;
3、
三、
四、
今天分析到此结束,后面会持续分享,敬请期待!