1.發佈配置
打開apollo新建項目apollo-quickstart
新建配置項sms.enable
發佈配置項
2.代碼實現
2.1.新建Maven工程
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.0-alpha1</version>
<scope>test</scope>
</dependency>
2.2.編寫測試類GetConfigTest
新建cn.itcast.apollo.quickstart包,添加測試類GetConfigTest
添加如下代碼讀取sms.enable的值
Config config = ConfigService.getAppConfig();
String someKey = "sms.enable";
String value = config.getProperty(someKey,null);
System.out.println("sms.enable:"+value);
2.3.配置VM options,設置系統屬性
-Dapp.id=apollo-quickstart -Denv=DEV -Ddev_meta=http://localhost:8080
運行GetConfigTest,打開控制檯,觀察輸出結果,配置讀取成功