nacos-group / nacos-spring-boot-project

Nacos ECO Project for Spring Boot
Apache License 2.0
785 stars 423 forks source link

springboot+nacos,无法auto-refresh #130

Open gyjx opened 4 years ago

gyjx commented 4 years ago

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

application.properties image

image

image

image

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

chuntaojun commented 4 years ago

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

gyjx commented 4 years ago

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

chuntaojun commented 4 years ago

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

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

gyjx commented 4 years ago

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

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

thinwonton commented 3 years ago

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 commented 3 years ago

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

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

wengieeee commented 3 years ago

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

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

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

thinwonton commented 3 years ago

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

Anthony-Dong commented 3 years ago

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);