Skip to content
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作为配置中心,properties文件无法读取$, @NacosValue #269

Closed
caijunqian opened this issue Nov 5, 2022 · 1 comment
Closed

Comments

@caijunqian
Copy link

caijunqian commented Nov 5, 2022

版本:

com.alibaba.boot
nacos-config-spring-boot-starter
0.2.8

问题:
使用properties类型文件作为springboot的启动配置,
配置 :test.password=123$456
使用:

@NacosValue(value = "${test.password:}", autoRefreshed = true)
    public void setPassword(String password) {
        System.out.println(password);
    }

项目启动的时候无法读取到123$456这个值

使用转义符: test.password=123\$456
项目启动后能读取到test.password=123$456
但是,更新nacos 配置的时候,无法做到自动刷新,
需要更改成配置test.password=123\\$456才能正常读取到test.password=123$456

通过源码跟踪发现,第一次启动和后续自动刷新时进入的方法不同

class:NacosValueAnnotationBeanPostProcessor

    private Object resolveNotifyValue(String nacosValueExpr, String key, String newValue) {
        String spelExpr = nacosValueExpr.replaceAll("\\$\\{" + key + "}", newValue);
        return this.resolveStringValue(spelExpr);
    }

    private Object resolveStringValue(String strVal) {
        String value = this.beanFactory.resolveEmbeddedValue(strVal);
        return this.exprResolver != null && value != null ? this.exprResolver.evaluate(value, this.exprContext) : value;
    }

有何解决方法,求助!

@caijunqian caijunqian changed the title nacos作为配置中心,properties文件无法读取$ nacos作为配置中心,properties文件无法读取$, @NacosValue Nov 5, 2022
@caijunqian
Copy link
Author

issue提错项目了,在nacos-spring-project中,有hxd提过了:nacos-group/nacos-spring-project#293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant