增加nacos你配的账号密码
spring:
cloud:
nacos:
username: your-username
password: your-password
不知道你这个问题是否已经解决, 如果还没有解决的话:添加【spring.profiles.active】配置,如下所示:
spring:
application:
name: nacos-config
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 # Nacos作为服务注册中心地址
config:
server-addr: 127.0.0.1:8848 # Nacos作为配置中心地址
file-extension: yml # 指定yaml格式的配置
profiles:
active: dev # 环境标识
访问:
http://localhost:18203/getValue 如下图所示: 将【spring.profiles.active】配置改为【pro】再次访问:
Group在Nacos中是用来对Data ID做集合管理的重要概念。
得到两个配置文件
在config下增加一条group的配置,指定配置文件所在的group,首先配置为【DEV_GROUP】
spring:
application:
name: nacos-config
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 # Nacos作为服务注册中心地址
config:
server-addr: 127.0.0.1:8848 # Nacos作为配置中心地址
file-extension: yml # 指定yaml格式的配置
prefix: nacos-config-test
group: DEV_GROUP
访问:http://localhost:18203/getValue 如下图所示:
将【group】配置成【PRO_GROUP】,再次访问:
根据参考资料中提供的内容,我们可以在 bootstrap.yml 文件中添加以下配置项来启用鉴权:
spring:
application:
name: nacos-config
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 # Nacos作为服务注册中心地址
config:
server-addr: 127.0.0.1:8848 # Nacos作为配置中心地址
file-extension: yml # 指定yaml格式的配置
prefix: nacos-config-test
group: DEV_GROUP
access-key: your_access_key # 访问鉴权的 Access Key
secret-key: your_secret_key # 访问鉴权的 Secret Key
enable-remote-sync-config: true # 启用远程同步配置功能
在上述配置中,我们添加了 access-key 和 secret-key 字段,分别用于访问鉴权的 Access Key 和 Secret Key。你需要将它们替换为实际的访问鉴权信息。
此外,为了启用远程同步配置功能,我们还设置了 enable-remote-sync-config 为 true。
请注意,根据你的实际需求,还可能需要调整其他配置项,比如 prefix 和 group。你需要根据具体情况进行调整。
希望以上解答能够对你有帮助,如果你还有其他问题,请随时提问。