JAVA全系列 教程
3762个小节阅读:7094.7k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
<dependencies>
<!-- 引入Eureka client依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- 引入 config 依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- 引入 web 依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
</dependencies>
xxxxxxxxxx
spring:
application:
name: config-client
cloud:
config:
label: master
name: config
profile: dev
# 上述综合 master分支上config-dev.yml的配置文件
# http://localhost:3344/master/config-dve.yml
uri: http://localhost:3344
server:
port: 3366
eureka:
client:
# 表示是否将自己注册到Eureka Server
register-with-eureka: true
# 示是否从Eureka Server获取注册的服务信息
fetch-registry: true
# Eureka Server地址
service-url:
defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
instance:
instance-id: cloud-config-center
prefer-ip-address: true
management:
endpoints:
web:
exposure:
include: "*"
xxxxxxxxxx
/**
* 主启动类
*/
@Slf4j
@EnableEurekaClient
@SpringBootApplication
public class ConfigClient3366 {
public static void main(String[] args) {
SpringApplication.run(ConfigClient3366.class,args);
log.info("********** ConfigClient3366 启动成功 *********");
}
}
xxxxxxxxxx
@RefreshScope
@RestController
public class ConfigClientController {
@Value("${config.info}")
private String configInfo;
/**
* 获取配置
* @return
*/
@GetMapping("/configinfo")
public String getConfigInfo(){
return configInfo;
}
}
注意: 利用消息总线触发一个服务端ConfigServer的/bus/refresh端点,而刷新所有客户端的配置。
xxxxxxxxxx
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
xxxxxxxxxx
rabbitmq:
host: 192.168.66.101
port: 5672
username: guest
password: guest
http://localhost:3355/actuator/busrefresh
指具体某个实例生效而不是全部
xxxxxxxxxx
http://localhost:3355/actuator/busrefresh/config-client:3355