程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了@RefreshScope不起作用-Spring Boot大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决@refreshScope不起作用-Spring Boot?

开发过程中遇到@refreshScope不起作用-Spring Boot的问题如何解决?下面主要结合日常开发的经验,给出你关于@refreshScope不起作用-Spring Boot的解决方法建议,希望对你解决@refreshScope不起作用-Spring Boot有所启发或帮助;

尝试改用@ConfigurationProperties。例如

@ConfigurationPropertIEs(prefix="config")
public class CloudConfig {

    private Integer count;

    public Integer count() {
        return this.count;
    }

    public voID setCount(Integer count) {
        this.count = count;
    }

}

Spring Cloud的参文档指出:

解决方法

我正在按照这里描述的方法进行操作:https : //github.com/jeroenbellen/blog-manage-and-reload-
spring-properties,唯一的区别是在我的情况下,这些属性正在多个类中使用,所以我有将它们全部放在一个实用程序类中CloudConfig,我使用getter引用其变量。这是该类的样子:

@Configuration
@refreshScope
public class CloudConfig {

    static volatile int count; // 20 sec

    @Value("${Config.count}")
    public void setCount(int count) {
        this.count = count;
    }

    public static int getCount() {
        return count;
    }

}

count在类似的其他类中使用该变量CloudConfig.getCount()。我可以在启动时很好地加载属性,但无法动态更新它们。谁能告诉我我做错了吗?如果不是制作该配置类,而是按照本教程描述的那样做就可以了,那么一切都可以正常工作,但是我很难适应它的用例。谁能告诉我我所缺少的吗?

大佬总结

以上是大佬教程为你收集整理的@RefreshScope不起作用-Spring Boot全部内容,希望文章能够帮你解决@RefreshScope不起作用-Spring Boot所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。