@Value static静态变量注入

@Component
public class Config {

    @Value("${config1}")
    private static String config1;
 
}

使用上面这种方式,config1会返回null
正确写法

@Component
public class Config {
 
    private static String config1;
 
    public static String getConfig1() {
        return config1;
    }
 
    @Value("${config1}")
    public void setConfig1(String config1) {
        Config.config1 = config1;
    }
}

 

posted @ 2020-06-29 09:46  天天代码码天天  阅读(8)  评论(0编辑  收藏  举报  来源