1.apollo配置中心环境搭建:
夸克网盘中有: apollo-quick-start-1.5.0.zip ,上传CentOS 使用 yum unzip 安装unzip命令,然后
进行解压,
修改demo.sh里面连接数据库地址信息,
然后使用 ./demo.sh start 命名启动,
访问地址: 192.168.3.128:8070
账号:apollo
密码: admin
2.引入依赖:
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>2.0.1</version>
</dependency>
3.配置application
app:
id: test-config-server #指定apollo配置中心中的appid
apollo:
meta: http://192.168.3.128:8080
bootstrap:
namespaces: application,application.yaml,application.yml
# 在应用启动阶段,向Spring容器注入被托管的application.properties文件的配置信息
enabled: true
eagerLoad:
# 将Apollo配置加载提到初始化日志系统之前
enabled: true
server:
port: 8989
spring:
application:
name: test-config-server
4.测试
package com.tomdd;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class ApolloServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ApolloServiceApplication.class, args);
}
@Value("${swagger.base-url}")
private String baseUrl;
@ApolloConfig
private Config config;
@GetMapping("/testInfo")
public String testInfo() {
return "swagger扫描范围:"+baseUrl;
}
}