【SpringBoot+SpringCloud】nacos配置管理问题解决
nacos使用bootstrap.yaml
进行nacos配置管理,启动时报错:
Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
使用nacos进行配置管理需要用到spring-cloud-config
,在官方文档里可以看见:
还需要
bootsrap
,需要额外引入
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
并且在bootstrap
配置文件中增加配置项:
spring.config.import: nacos:classdemo-order-dev.yaml
如果模块中同时有application.yml
和bootstrap.yml
文件要注销掉application.yml
内容,将其复制到nacos创建配置的配置内容里
注意id和服务名称的对应:
spring.config.import
的id对应配置管理的id
spring.application.name
的id对应服务管理的服务名
重新启动,成功。