1:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
2:
@SpringBootApplication
@EnableEurekaClient
public class ConfigClientMain3355 {
public static void main(String[] args) {
SpringApplication.run(ConfigClientMain3355.class,args);
}
}
3: refreshScope 用来刷新配置,当git上发生改变,通知客户端
@RestController
@RefreshScope
public class ConfigClientController
{
@Value("${config.info}")
private String configInfo;
@Value("${server.port}")
private String serverPort;
//http://localhost:3355/configInfo
@GetMapping("/configInfo")
public String getConfigInfo()
{
return configInfo+",serverPort = "+serverPort;
}
}
4: 使用bootstrap.yml
server:
port: 3355
spring:
application:
name: config-client
cloud:
#Config客户端配置
config:
label: main #分支名称
name: config #配置文件名称
profile: dev #读取后缀名称 上述3个综合:main分支上config-dev.yml的配置文件被读取http://localhost:3344/main/config-dev.yml
uri: http://localhost:3344 #配置中心地址
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
#服务注册到eureka地址
eureka:
client:
service-url:
defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
# 暴露监控端点
management:
endpoints:
web:
exposure:
include: "*"