refresh作用域不更新属性,而是刷新bean本身

h9vpoimq  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(128)

我正在尝试使用actuator刷新刷新作用域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);
    }

}

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

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题