|
|
## 配置中心客户端,须知:
|
|
|
|
|
|
## 一、bootstrap.yml 模板
|
|
|
|
|
|
将客户端原来的 application.yml 改成 bootstrap.yml
|
|
|
|
|
|
```yml
|
|
|
# spring 配置
|
|
|
spring:
|
|
|
cloud:
|
|
|
config:
|
|
|
# url地址记得修改
|
|
|
uri: http://localhost:8888
|
|
|
# 和git中的配置文件里面的服务名,一致
|
|
|
name: cgonms-arrival
|
|
|
# 分支
|
|
|
label: master
|
|
|
# 开发环境
|
|
|
profile: dev
|
|
|
# 与配置中心的security一致
|
|
|
username: admin
|
|
|
password: 123456
|
|
|
|
|
|
```
|
|
|
|
|
|
## 注:
|
|
|
|
|
|
git中配置文件的名称,注意点: 查看
|
|
|
|
|
|
http://118.31.66.166:8099/cloud-config/cloud-config-center/tree/master/respo
|
|
|
|
|
|
## 二、在git中的yml配置文件,一定要有
|
|
|
|
|
|
```yml
|
|
|
spring:
|
|
|
rabbitmq:
|
|
|
host: 192.168.1.63
|
|
|
port: 5672
|
|
|
username: mrz
|
|
|
password: vmvnv1v2
|
|
|
|
|
|
# boot admin
|
|
|
management:
|
|
|
endpoints:
|
|
|
enabled-by-default: true
|
|
|
web:
|
|
|
exposure:
|
|
|
include: "*"
|
|
|
endpoint:
|
|
|
health:
|
|
|
show-details: always
|
|
|
shutdown:
|
|
|
enabled: true
|
|
|
```
|
|
|
|
|
|
## 三、配置中心客户端的 pom
|
|
|
|
|
|
```xml
|
|
|
<dependency>
|
|
|
<groupId>org.springframework.boot</groupId>
|
|
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
|
|
</dependency>
|
|
|
<dependency>
|
|
|
<groupId>org.springframework.cloud</groupId>
|
|
|
<artifactId>spring-cloud-bus</artifactId>
|
|
|
</dependency>
|
|
|
<dependency>
|
|
|
<groupId>org.springframework.cloud</groupId>
|
|
|
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
|
|
|
</dependency>
|
|
|
```
|
|
|
|
|
|
## 四、配置中心客户端的启动类
|
|
|
|
|
|
```java
|
|
|
/**
|
|
|
* 和添加配置中心服务之前,一样。没有修改
|
|
|
*/
|
|
|
@EnableScheduling
|
|
|
@SpringBootApplication
|
|
|
@MapperScan("com.sunyo.wlpt.cgonms.arrival.mapper")
|
|
|
@EnableFeignClients
|
|
|
@EnableEurekaClient
|
|
|
@EnableTransactionManagement
|
|
|
public class CgonmsArrivalApplication {
|
|
|
public static void main(String[] args) {
|
|
|
SpringApplication.run(CgonmsArrivalApplication.class, args);
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
## 五、注意点
|
|
|
|
|
|
任何使用 @value 读取配置文件信息的所在类的上面,必须要添加上 @RefreshScope
|
|
|
|
|
|
```java
|
|
|
@RestController
|
|
|
@RefreshScope
|
|
|
public class IndexController {
|
|
|
@Value("${server.ip}")
|
|
|
private String ip;
|
|
|
|
|
|
@GetMapping("/index")
|
|
|
public String index(){
|
|
|
return ip;
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
...
|
...
|
|