微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决刷新范围不更新属性而是刷新 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 举报,一经查实,本站将立刻删除。