虛擬機ip爲: 192.168.102.140html
步驟1 經過mysql客戶端, 如Navicat, 鏈接linux中的數據庫.java
步驟2 導入sqlmysql
經過各類MySQL客戶端導入sql/apolloportaldb.sql便可。linux
默認端口爲: 8070git
./demo.sh startgithub
注意: 腳本會在本地啓動3個服務,分別使用8070, 8080, 8090端口,請確保這3個端口當前沒有被使用。spring
選擇 SringWeb的依賴sql
<dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>1.1.0</version> </dependency>
注意: 鏈接apollo界面的端口爲8090, 鏈接server端口爲 8080數據庫
#appId 同來區別不一樣的配置
app.id=SampleApp
#apollo服務器地址
apollo.meta=http://192.168.102.140:8080
@Configuration @EnableApolloConfig public class AppConfig { @Bean public TestJavaConfigBean javaConfigBean() { return new TestJavaConfigBean(); } }
public class TestJavaConfigBean { @Value("${timeout:100}") private int timeout; private int batch; @Value("${batch:200}") public void setBatch(int batch) { this.batch = batch; } public int getTimeout() { return timeout; } public int getBatch() { return batch; } }
/** * @author c-can-z */ @RestController public class TestController { @Autowired private TestJavaConfigBean testJavaConfigBean; @RequestMapping("get") public String get(){ int batch = testJavaConfigBean.getBatch(); int timeout = testJavaConfigBean.getTimeout(); return "batch:"+batch+", timeout:"+timeout; } }
該文章爲apollo的最簡單的使用, 若是想要了解更多, 仍是從官方文章獲取.windows
目前的配置中 SpringCloud-Config, zookeeper等, 使用都是大同小異
有疑問留言, 我會及時回覆
代碼之路, 道阻且長, 且行且珍惜