1.创建srpingBoot的工程
2.pom文件如下,如果出现无法正确读取nacos的配置,很大程度是因为jar包的版本问题导致,当前我使用的是
springBoot的版本:
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.18</version><relativePath/> <!-- lookup parent from repository --> </parent>
nacos相关的版本
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId><version>2021.0.1.0</version> </dependency> <dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId><version>2021.0.1.0</version> </dependency>
3.yaml文件配置:
spring:profiles:active: devapplication:name: cloud-gatewaycloud:nacos:discovery:server-addr: localhost:8848namespace: 1c88f9d9-1f33-4460-9764-35603afb851ausername: nacospassword: nacosconfig:server-addr: localhost:8848namespace: 1c88f9d9-1f33-4460-9764-35603afb851ausername: nacospassword: nacosfile-extension: yamlextension-configs:- data-id: application-dev.yaml # group: DEFAULT_GROUP # refresh: trueconfig:import: nacos:application-dev.yamllogging:level: # org: # springframework: # boot: # autoconfigure: # logging: DEBUGcom.alibaba.cloud.nacos.configdata: debug server:port: 8091