
创建Maven工程,修改为SpringBoot
导入依赖
>
>org.springframework.cloud >
>spring-cloud-config-server >
>
>
>org.springframework.cloud >
>spring-cloud-starter-netflix-eureka-client >
>
添加注解 在启动类上
@EnableConfigServer
编写配置文件(Git的操作)
spring:
cloud:
config:
server:
git:
basedir: D:\basedir # 本地仓库的地址
username: zjw_2301211@126.com # 远程仓库用户名
password: z123123 # 远程仓库密码
uri: https://gitee.com/zhengdaxian/config-resp.git # 远程仓库地址
http://localhost:8099/master/bootstrap-xxs.yml
测试(http://localhost:port/{label}/{application}-{profile}.yml)
label 就是你远程仓库分支名称
application 文件名称
“-” 中横线 必须有
profile 必须有:如果没有profile后缀 也必须随便写一个,如果有就拉取你自己的profile(dev、test、pre、pro)
bootstrap.yml 优先级别最高,如果要采用我们的config,配置文件必须采用bootstrap.yml
>
>org.springframework.cloud >
>spring-cloud-config-client >
>
编写配置文件
# 指定Eureka服务地址
eureka:
client:
service-url:
defaultZone: http://root:root@localhost:8761/eureka,http://root:root@localhost:8762/eureka
#指定服务的名称
spring:
application:
name: CUSTOMER-${version}
cloud:
config:
discovery:
enabled: true #开启远程配置
service-id: CONFIG #访问config服务器
profile: dev #远程配置文件的后缀
version: v1
# CONFIG -> CUSTOMER-v1-dev.yml

导入依赖
>
>org.springframework.cloud >
>spring-cloud-starter-bus-amqp >
>
编写配置文件连接RabbitMQ信息
spring:
rabbitmq:
host: 192.168.199.109
port: 5672
username: test
password: test
virtual-host: /test
导入依赖
>
>org.springframework.boot >
>spring-boot-starter-actuator >
>
management:
endpoints:
web:
exposure:
include: "*"
为customer添加一个controller
@RestController
@RefreshScope //刷新
public class CustomerController {
@Value("${env}")
private String env;
@GetMapping("/env")
public String env(){
return env;
}
}
测试
内网穿透的官网https://natapp.cn/
注册登录
购买一个免费的隧道。
下载客户端,并复制config.ini文件,在文件中指定authtoken
启动exe文件,并测试使用域名访问config接口
配置Gitee中的WebHooks
给Config添加一个过滤器
直接去代码中找到Filter