1.配置类需要让spring管理
2.set方法不要加static
3.如果静态属性是private修饰,则在使用的时候,需要 类名.getXXX方法
如果静态属性是public修饰,则在使用的时候,需要 类名.属性名
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class TestConfig {private static String url ;public static String getUrl() {return url;}@Value("${sendMessUrl}")public void setUrl(String url) {TestConfig.url = url;}
}
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class TestConfigController {@GetMapping("/testConfig")public String testConfig() {return TestConfig.getUrl();}
}
sendMessUrl: XXX