nacos属性自动刷新的问题

关于属性自动刷新

    两种方案,参考 @RefreshScope + @Value @RefreshScope + @ConfigurationProperties 问题:在nacos上修改配置文件,程序成功刷新,但刷新一次后,报错longPolling Error,导致后续的修改无法刷新到。解决方案:将 2.2.4版本升级到2.2.5。 <!-- nacos 服务注册与发现 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2.2.5.RELEASE</version> </dependency> <!-- nacos 配置中心 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <version>2.2.5.RELEASE</version> </dependency> 只自动刷新nacos默认加载的配置,如 ${spring.application.name}.${file-extension:properties} ${spring.application.name}-${profile}.${file-extension:properties} 而对于其他的自定义加载的配置,需要额外配置refresh:true,如下 spring: profiles: active: dev application: name: liveness cloud: nacos: server-addr: 127.0.0.1:8848 username: nacos password: nacos discovery: namespace: xxxx group: liveness config: namespace: xxxx group: liveness file-extension: yml extension-configs: - dataId: ${ spring.profiles.active}-${ spring.application.name}-database.yml group: liveness refresh: true # 手动开启自动刷新 - dataId: ${ spring.profiles.active}-${ spring.application.name}-redis.yml group: liveness refresh: true - dataId: ${ spring.profiles.active}-${ spring.application.name}-properties.yml group: liveness refresh: true refresh-enabled: true
经验分享 程序员 微信小程序 职场和发展