配置@ConfigurationProperties后读取yml文件的参数值为null的最大可能原因

问题:在Springboot项目中,配置@ConfigurationProperties后读取yml文件的参数值为null,检测了好几遍又没有写错,一直读取不到,后来经过很长时间的一个一个的检查,发现,在做set方法的时候,写成了静态的set方法了,把static标识删除就正常读取了。

    public static String getProfile()
    {
        return profile;
    }

    public void setProfile(String profile)
    {
        this.profile = profile;
    }

*注意看,get前是static标识,set直接是void方法,这样写才是正确的。

正在加载评论...