一.普通的dao,service对应的实例bean不存在
报错示例:
1.Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class。
2.
解决方案:
1.确实不存在,加进去就好了
2.类存在,但是spring没有扫描到,注意启动类所在位置,springboot默认扫描的是启动类所在目录下的子包和类,如下图1.2所示。另外可以使用@componentScan这个注解指定扫描的包:示例@componentScan({“xxx.xx”,"xxx.xx"})

二.由于bean的加载顺序和配置文件的关系
1.请参考以下博文
https://blog.csdn.net/J080624/article/details/80508606
https://blog.csdn.net/zhongzunfa/article/details/81988807
https://blog.csdn.net/leileibest_437147623/article/details/80898878

本文解析了SpringBoot中常见的Bean加载错误,包括DataSource配置失败及Bean加载顺序问题,并提供了解决方案,如检查DataSource配置、使用@componentScan注解指定扫描路径,以及调整Bean的加载顺序。

861

被折叠的 条评论
为什么被折叠?



