在spring mvc架構中,若是但願在程序中直接使用properties中定義的配置值,一般使用一下方式來獲取:spring
@Value("${tag}") private String tagValue;
可是取值時,有時這個tagvalue爲NULL,可能緣由有:架構
private static String tagValue; //錯誤 private final String tagValue; //錯誤
@Component //遺漏 class TestValue{ @Value("${tag}") private String tagValue; }
@Component class TestValue{ @Value("${tag}") private String tagValue; } class Test{ ... TestValue testValue = new TestValue() }
class Test{ @AutoWired TestValue testValue }