配置中心使用Apollo使用
原创
©著作权归作者所有:来自51CTO博客作者达达智能的原创作品,请联系作者获取转载授权,否则将追究法律责任
window下使用
服务端使用
服务端代码下载链接
apollo-quick-start-1.6.1.zip
git 运行
http://localhost:8070/登录
新建客户端
客户端使用
pom.xml
<!-- apollo 携程apollo配置中心框架 -->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-core</artifactId>
<version>1.6.0</version>
</dependency>
app.properties
apollo-env.properties
local.meta=http://localhost:8080
dev.meta=http://localhost:8080
fat.meta=${fat_meta}
uat.meta=${uat_meta}
lpt.meta=${lpt_meta}
pro.meta=${pro_meta}
重点:
server.properties
CloudTestApplication.java
@Configuration
@EnableApolloConfig
@SpringBootApplication
@EnableAutoConfiguration
public class CloudTestApplication {
public static void main(String[] args) {
SpringApplication.run(CloudTestApplication.class, args);
}
}
TestController.java
@RestController
@EnableApolloConfig({"mstest"})
public class TestController {
@Value("${server.port}")
int port;
@Value("${mstest.port:1234}")
private int msPort;
@RequestMapping("hello")
public String hello() {
return msPort + "";
}
}