nacos-spring-boot-project icon indicating copy to clipboard operation
nacos-spring-boot-project copied to clipboard

springboot+nacos,无法auto-refresh

Open gyjx opened this issue 4 years ago • 9 comments

nacos:1.2.1 nacos-config-spring-boot-starter:0.2.7

application.properties image

image

image

image

经测试发现,nacos配置中心的person.name值或者是server.port变动,客户端无法感知?依然是老值,请问如何解决?

gyjx avatar May 27 '20 07:05 gyjx

需要使用@NacosValue(xxx, autoRefresh=true)

chuntaojun avatar May 27 '20 07:05 chuntaojun

那如果配置的是mysql,redis使用springboot自动配置,如何解决呢?

gyjx avatar May 27 '20 08:05 gyjx

那如果配置的是mysql,redis使用springboot自动配置,如何解决呢?

你想redis以及mysql的配置是可变动的?

chuntaojun avatar May 27 '20 08:05 chuntaojun

那如果配置的是mysql,redis使用springboot自动配置,如何解决呢?

你想redis以及mysql的配置是可变动的? 是的,例如我可以调整连接池大小等操作

gyjx avatar May 27 '20 11:05 gyjx

nacos:1.3.3 nacos-config-spring-boot-starter:0.2.7/0.2.6/0.2.4

使用 @NacosValue(xxx, autoRefresh=true)都不可以热更新 但是,nacos-config-spring-boot-starter:0.2.1 可以

thinwonton avatar Sep 26 '20 02:09 thinwonton

nacos:1.2.x nacos-config-spring-boot-starter:0.2.7/0.2.6

可以热更新配置。看来是nacos-client 1.3.x不支持

thinwonton avatar Sep 26 '20 02:09 thinwonton

nacos:1.2.x nacos-config-spring-boot-starter:0.2.7/0.2.6

可以热更新配置。看来是nacos-client 1.3.x不支持

请问有解决吗?我这边也是不能自动刷新配置 版本0.2.7

wengieeee avatar Oct 29 '20 11:10 wengieeee

nacos:1.2.x nacos-config-spring-boot-starter:0.2.7/0.2.6 可以热更新配置。看来是nacos-client 1.3.x不支持

请问有解决吗?我这边也是不能自动刷新配置 版本0.2.7

nacos-spring-context 升级为1.0.0。。。支持 client 1.3.x

https://github.com/nacos-group/nacos-spring-project/releases

thinwonton avatar Oct 30 '20 03:10 thinwonton

nacos:1.2.x nacos-config-spring-boot-starter:0.2.7/0.2.6 可以热更新配置。看来是nacos-client 1.3.x不支持

请问有解决吗?我这边也是不能自动刷新配置 版本0.2.7

nacos-spring-context 升级为1.0.0。。。支持 client 1.3.x

https://github.com/nacos-group/nacos-spring-project/releases

目前试了试将nacos-spring-context 升级为1.0.0,但是发现抛出异常的原因是 nacos在获取 type的时候默认是根据 dataId 走的,也就是我们目前使用的注解 @NacosPropertySource 无法修改readConfigTypeFromDataId值,只能通过 @EnableNacosConfig注解修改!业务上不允许随便改这些注解依赖! 但是将nacos版本降级为 1.2.0 是可以解决问题的,我们项目的spring-cloud-starter-alibaba-nacos-discovery#2.2.3.RELEASE,导致引入nacos-config-spring-boot-starter#0.27版本造成的问题,感谢帮助

问题代码: com.alibaba.nacos.spring.core.env.AbstractNacosPropertySourceBuilder#doBuild

String type = null;

if (NacosUtils.isReadTypeFromDataId()) {
    type = NacosUtils.readFileExtension(dataId);
}
else {
    type = ((ConfigType) runtimeAttributes.get(CONFIG_TYPE_ATTRIBUTE_NAME))
            .getType();
}

问题代码: com.alibaba.nacos.spring.context.annotation.config.NacosConfigBeanDefinitionRegistrar#registerBeanDefinitions

AnnotationAttributes attributes = fromMap(
    metadata.getAnnotationAttributes(EnableNacosConfig.class.getName()));

boolean readTypeFromDataId = attributes.getBoolean("readConfigTypeFromDataId");
NacosUtils.setReadTypeFromDataIdIfNull(readTypeFromDataId);

Anthony-Dong avatar Mar 24 '21 09:03 Anthony-Dong