1.引入依賴
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.3.0</version>
</dependency>
2.添加配置
# app.id:AppId是應用的身份信息,是配置中心獲取配置的一個重要信息。
# apollo.bootstrap.enabled:在應用啓動階段,向Spring容器注入被託管的application.properties文件的配置信息。
# apollo.bootstrap.eagerLoad.enabled:將Apollo配置加載提到初始化日誌系統之前。
# my.test: 等等演示讀取Apollo中的配置
server:
port: 8761
app:
id: springboot-apollo
apollo:
meta: http://127.0.0.1:8080
bootstrap:
enabled: true
eagerLoad:
enabled: true
my:
test: 1
3.測試類
@RestController
public class HelloController {
@Value("${my.test}")
String test;
@GetMapping("hi")
public String hi(String name) {
System.out.println("name:" + name);
return test + ":"+name;
}
}
4.Apollo配置
5.測試
啓動項目,訪問http://localhost:8761/hi?name=yfy
可以看到讀取到了apollo中的對應配置。