admin管理员组文章数量:1571364
今早在集成nacos时启动报如下错:
Description:
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
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
排查一:检查nacos中配置的database的配置
上面的错误描述明确的说了是datasource的url读不到,那么第一反应是去检查一下是不是配置错误了,nacos中配置的文件检查了datasource的所有属性没有问题
⚠️注意:这里可能会踩坑的是mysql的版本在8以下和8以上driver-class-name是不一样的,8及以上需要在加上cj,还需要在url后面加上时区,这里我检查了一下我的mysql是8.0
排查二:检查bootstrap.yml的配置是否和nacos中内容一致
既然排除了我的数据库配置没问题,那么就需要检查一下我的项目是否能拉到nacos的配置
对比如下,仔细检查后配置没有问题
排查三:检查有无 spring-cloud-starter-bootstrap依赖
在出问题的时候查阅了多方资料,都忽略了这个,因为检查了自己的pom包里面已经有了spring-cloud-starter的依赖,就没有考虑过加bootstrap的依赖,最后实在解决不了我的错,就报着试一下的心态去加了下面的依赖,好了!
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
为什么要加bootstrap的依赖?
我在项目中新加了一个bootstrap.yml,在这之前我只了解到bootstarp.yml的加载优先级比bootstrap.properties更高,但是springboot项目中如果没有spring-cloud-context或者spring-cloud-starter-bootstrap的依赖的话是不会去读取bootstrap.properties的,只会去读application.properties,
spring boot 2.4版本以下加
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
spring boot 2.4版本以上加
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
本文标签: 报错启动时SpringCloudNacos
版权声明:本文标题:springCloud集成nacos启动时报错排查 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1727689822a1125740.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论