-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nacos配置中心 无法加载配置 #3904
Comments
|
@Comven 我试了,还是不行,加载不到 nacos 里面的配置。 |
谢谢 @Comven 解决了,需要按照如下方式配置方可读取到数据。我个人感觉配置起来还是相对比较麻烦的,不够友好。 spring.config.import[0]=nacos:application.properties?refresh=true spring.cloud.nacos.config.server-addr=172...19:8848 spring.cloud.nacos.config.shared-configs[0].data-id=${spring.application.name}.properties spring.cloud.nacos.config.shared-configs[1].data-id=application.properties |
spring.cloud.nacos.config.shared-configs[0].data-id=${spring.application.name}.properties spring.cloud.nacos.config.shared-configs[1].data-id=application.properties shared-configs 已经不推荐使用,未来版本会废弃,统一通过spring.config.import进行导入 spring.config.import[0]=nacos:${spring.application.name}.properties?group=DEFAULT_GROUP&refreshEnabled=true |
ConfigurationProperties 注解将NacosConfigProperties发布为了一个SpringBean,但是实际上spring cloud alibaba加载nacos的时间点是在所有Bean开始初始化前进行,将nacos中的属性加载为PropertiesSource,其内部会创建一个NacosConfigProperties对象,但并不是一个SpringBean, 将NacosConfigProperties发布为一个SpringBean并没有实际用途,SCA和Nacos交互是并不依赖该Spring Bean,后续版本会对内部的组件进行进一步简化 |
@shiyiyue1102 @Comven 我也是试了,还是不行。感觉弄得越来越麻烦了,配置文件应该越简单越好。而且这个拼接参数个数越多就越长,整得像长城一样,一眼看不到头(说实话,也不知道咋想的)
|
我的配置,目前还是在 bootstrap.yml 中配置,暂时没发现什么问题。 # spring cloud alibaba 基础设施配置
spring:
config:
activate:
on-profile: alibaba
import:
- nacos:dante-cloud-environment.yaml?group=${PROFILE:@profile@}
- nacos:dante-cloud-platform.yaml?group=common
- nacos:dante-cloud-database-${DATABASE:@database@}.yaml?group=common
- nacos:dante-cloud-database.yaml?group=common
- nacos:dante-cloud-redis.yaml?group=common
- nacos:dante-cloud-cache.yaml?group=common
- nacos:dante-cloud-rest.yaml?group=common
- nacos:dante-cloud-kafka.yaml?group=common
- nacos:${spring.application.name}.yaml?group=service
cloud:
nacos:
username: ${ALIBABA_USERNAME:@alibaba.username@}
password: ${ALIBABA_PASSWORD:@alibaba.password@}
config:
namespace: ${ALIBABA_NAMESPACE:@alibaba.namespace@}
server-addr: ${ALIBABA_CONFIG_SERVER_ADDR:@alibaba.config.server-addr@}
file-extension: yaml
discovery:
namespace: ${ALIBABA_NAMESPACE:@alibaba.namespace@}
server-addr: ${ALIBABA_DISCOVERY_SERVER_ADDR:@alibaba.discovery.server-addr@}
sentinel:
transport:
port: 8719
dashboard: ${ALIBABA_SENTINEL_SERVER_ADDR:@alibaba.sentinel.server-addr@} 代码地址,参见 |
指定spring.cloud.nacos.config.namespace=xxx. 指定命名空间ID,不设置的情况加载的是public命名空间下的配置, |
@shiyiyue1102 非常感谢 |
Spring Cloud Alibaba 2023.0.1.3
Spring Cloud 2023.0.3.
Spring Boot 3.2.11
JDK21
spring-cloud-starter-alibaba-nacos-config 2023.0.1.3
nacos 配置中心的配置加载不到
The text was updated successfully, but these errors were encountered: