标签:Apollo name 入门 springframework import org apollo com SpringBoot
基础概念
- 官方文档(官网介绍较为详细,不再赘述)
https://www.apolloconfig.com/#/zh/design/apollo-introduction
SpringBoot集成
一.官网给予了基础的Quick Start,可参考学习入门 ,(win平台启动可以使用git客户端执行sh脚本)
$ sh ./demo.sh start
Windows new JAVA_HOME is: /d/DevProgram/Java/jdk
==== starting service ====
Service logging file is ./service/apollo-service.log
Started [1121]
Waiting for config service startup...
看到Started [1121]即表示成功!
二.这里给出在springboot工程中如何使用的简单demo
1.首先参考Quick Start文档,搭建基础环境,包括 Apollo config应用和数据库等
2.新建springboot 工程,导入web依赖和Apollo client依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<groupId>com.ggq</groupId>
<artifactId>springboot-apollo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- web功能起步依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- apollo 客户端依赖-->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
</project>
2.主启动类
package com.ggq;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
@SpringBootApplication
@EnableApolloConfig //此处开启apollo配置
public class ApolloClientStart {
public static void main(String[] args) {
SpringApplication.run(ApolloClientStart.class,args);
}
}
3.构建基础配置文件,指定apollo配置中心地址和应用本身id等
server:
port: 8081
app:
id: springboot-apollo
apollo:
meta: http://127.0.0.1:8080
bootstrap:
enabled: true
eagerLoad:
enabled: true
4.测试类
package com.ggq.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@Value( "${name}" )
private String name;
@RequestMapping("/name")
public String ReadName() {
return "我的名字是:"+this.name;
}
}
访问http://localhost:8081/name,可以得到我的名字是:张三 ,重新在apollo中配置name值无需重启,再次请求
http://localhost:8081/name,可得到我的名字是:李四
标签:Apollo,name,入门,springframework,import,org,apollo,com,SpringBoot 来源: https://www.cnblogs.com/sxblog/p/15489194.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。