springboot启动报错bean找不到怎么解决

      springboot启动报错bean找不到的原因解决

      一.普通的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。

      解决方案:

      1.确实不存在,加进去就好了

      2.类存在,但是spring没有扫描到,注意启动类所在位置,springboot默认扫描的是启动类所在目录下的子包和类,如下图1.2所示。另外可以使用@componentScan这个注解指定扫描的包:示例@componentScan({“xxx.xx”,“xxx.xx”})

      二.由于bean的加载顺序和配置文件的关系

      1.请参考以下博文

      https://www.yisu.com/article/222850.htm

      https://www.yisu.com/article/190698.htm

      https://www.yisu.com/article/229466.htm

      补充:Springboot启动报错之类文件具有错误的版本 61.0, 应为 52.0

      启动Springboot项目时候报错

      java: 无法访问org.springframework.boot.SpringApplication
      错误的类文件: /D:/Maven/apache-maven-3.6.3/repository/org/springframework/boot/spring-boot/3.0.0/spring-boot-3.0.0.jar!/org/springframework/boot/SpringApplication.class
      类文件具有错误的版本 61.0, 应为 52.0
      请删除该文件或确保该文件位于正确的类路径子目录中。

      原因

      SpringBoot使用了3.0或者3.0以上,因为Spring官方发布从Spring6以及SprinBoot3.0开始最低支持JDK17,所以仅需将SpringBoot版本降低为3.0以下即可。

      将SpringBoot版本降低为3.0以下 版本随意,刷新Maven重启即可

      以上就是springboot启动报错bean找不到怎么解决的详细内容,更多请关注www.sxiaw.com其它相关文章!