alibaba / nacos

an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
https://nacos.io
Apache License 2.0
30.07k stars 12.81k forks source link

静态变量动态刷新问题 #3165

Closed yangseal closed 4 years ago

yangseal commented 4 years ago

Issue Description

Type: bug report or feature request

Describe what happened (or what feature you want)

Describe what you expected to happen

How to reproduce it (as minimally and precisely as possible)

  1. public static boolean logSwitchOff; //日志开关,默认开启 @Value("${logSwitchOff:true}") public void setLogSwithOff(boolean logSwitchOff) { NacosConfiguration.logSwitchOff = logSwitchOff; }

  2. 静态属性变量不能动态刷新,需要通过手动获取一下才能刷新吗

Tell us your environment

nacos版本1.2.1

Anything else we need to know?

KomachiSion commented 4 years ago

Is it nacos' codes? I have no impression.

chuntaojun commented 4 years ago

You are using springboot or spring cloud or spring mvc

yangseal commented 4 years ago

springcloud @Value结合@RefreshScope

chuntaojun commented 4 years ago

Whether the log is printed: "Refresh Nacos config group=%s,dataId=%s,configInfo=%s" or "[{}] [notify-ok] dataId={}, group={}, md5={}, listener={}"

yangseal commented 4 years ago
类上面加了@RefreshScope
```
@Value("${useLocalCache:false}")
private volatile boolean useLocalCache;
@RequestMapping("/get")
public boolean get() {
    return useLocalCache;
}

   起了一个线程获取值改变
   `@PostConstruct
    public void init() {
        Thread t=  new Thread(new Runnable(){
            @Override
            public void run() {
                while(true){
                    System.out.println("useLocalCache测试-------:"+useLocalCache);
                    try {
                        TimeUnit.MILLISECONDS.sleep(10000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        t.setDaemon(true);
        t.start();
    }`
     在nacos配置中修改useLocalCache值,线程值打印无变化,通过http调用get接口,值发生变化,线程打印值如下,打印有问题

![image](https://user-images.githubusercontent.com/15855998/85493389-672a2e80-b609-11ea-9f01-3e2ed4ec3544.png)
chuntaojun commented 4 years ago

首先你有排查日志确定接收到了配置变更的刷新吗?如果有,那这个问题就脱离nacos了,而是spring-cloud的问题了应该

KomachiSion commented 4 years ago

No response from author, close issue