刷新范围不更新属性而是刷新 bean 本身

问题描述

我正在尝试使用执行器刷新刷新作用域 bean。需要刷新的类:

@ConfigurationProperties(prefix = "push-sync")
@RefreshScope
public class PushSyncProperties {

    private boolean available = true;
    private int maxSyncThreads = 5;
    private int maxRequestsPerSecond = 5;
    private int maxRetries = 10;
    private long initialRetryDelay = 7 * 1000L;
    private long maxRetryDelay = 8 * 60 * 60 * 1000L;
    private int retryBackOffMultiplier = 3;
    private long dbCheckInterval = 10 * 1000L;

    @postconstruct
    public void refresh()
    {
        log.info("Application Refreshed!");
        log.info(String.valueOf(maxSyncThreads));
    } 

pom 的一部分

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
            <version>2.2.3.RELEASE</version>
        </dependency>

和主类

@EnableConfigurationProperties({PushSyncProperties.class})
@EnableScheduling
@PropertySource("file:${push.sync.config}")
@SpringBootApplication
public class Application extends SpringBootServletinitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        String pushSyncConfigPath = SystemProperties.get("push.sync.config");
        return application.sources(Application.class)
                .properties(
                        "spring.config.location:classpath:/application.yml," + pushSyncConfigPath
                );
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }

}

但是,每当更改映射我的属性类的特定文件中的属性时,都会调用 postconstruct 函数,但永远不会更新该值。知道为什么吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)