虚拟机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等, 使用都是大同小异
有疑问留言, 我会及时回复
代码之路, 道阻且长, 且行且珍惜