正在显示
1 个修改的文件
包含
109 行增加
和
0 行删除
ReadMe.md
0 → 100644
| 1 | +## 配置中心客户端,须知: | ||
| 2 | + | ||
| 3 | +## 一、bootstrap.yml 模板 | ||
| 4 | + | ||
| 5 | +将客户端原来的 application.yml 改成 bootstrap.yml | ||
| 6 | + | ||
| 7 | +```yml | ||
| 8 | +# spring 配置 | ||
| 9 | +spring: | ||
| 10 | + cloud: | ||
| 11 | + config: | ||
| 12 | + # url地址记得修改 | ||
| 13 | + uri: http://localhost:8888 | ||
| 14 | + # 和git中的配置文件里面的服务名,一致 | ||
| 15 | + name: cgonms-arrival | ||
| 16 | + # 分支 | ||
| 17 | + label: master | ||
| 18 | + # 开发环境 | ||
| 19 | + profile: dev | ||
| 20 | + # 与配置中心的security一致 | ||
| 21 | + username: admin | ||
| 22 | + password: 123456 | ||
| 23 | + | ||
| 24 | +``` | ||
| 25 | + | ||
| 26 | +## 注: | ||
| 27 | + | ||
| 28 | +git中配置文件的名称,注意点: 查看 | ||
| 29 | + | ||
| 30 | +http://118.31.66.166:8099/cloud-config/cloud-config-center/tree/master/respo | ||
| 31 | + | ||
| 32 | +## 二、在git中的yml配置文件,一定要有 | ||
| 33 | + | ||
| 34 | +```yml | ||
| 35 | +spring: | ||
| 36 | + rabbitmq: | ||
| 37 | + host: 192.168.1.63 | ||
| 38 | + port: 5672 | ||
| 39 | + username: mrz | ||
| 40 | + password: vmvnv1v2 | ||
| 41 | + | ||
| 42 | +# boot admin | ||
| 43 | +management: | ||
| 44 | + endpoints: | ||
| 45 | + enabled-by-default: true | ||
| 46 | + web: | ||
| 47 | + exposure: | ||
| 48 | + include: "*" | ||
| 49 | + endpoint: | ||
| 50 | + health: | ||
| 51 | + show-details: always | ||
| 52 | + shutdown: | ||
| 53 | + enabled: true | ||
| 54 | +``` | ||
| 55 | + | ||
| 56 | +## 三、配置中心客户端的 pom | ||
| 57 | + | ||
| 58 | +```xml | ||
| 59 | +<dependency> | ||
| 60 | + <groupId>org.springframework.boot</groupId> | ||
| 61 | + <artifactId>spring-boot-starter-actuator</artifactId> | ||
| 62 | +</dependency> | ||
| 63 | +<dependency> | ||
| 64 | + <groupId>org.springframework.cloud</groupId> | ||
| 65 | + <artifactId>spring-cloud-bus</artifactId> | ||
| 66 | +</dependency> | ||
| 67 | +<dependency> | ||
| 68 | + <groupId>org.springframework.cloud</groupId> | ||
| 69 | + <artifactId>spring-cloud-stream-binder-rabbit</artifactId> | ||
| 70 | +</dependency> | ||
| 71 | +``` | ||
| 72 | + | ||
| 73 | +## 四、配置中心客户端的启动类 | ||
| 74 | + | ||
| 75 | +```java | ||
| 76 | +/** | ||
| 77 | + * 和添加配置中心服务之前,一样。没有修改 | ||
| 78 | + */ | ||
| 79 | +@EnableScheduling | ||
| 80 | +@SpringBootApplication | ||
| 81 | +@MapperScan("com.sunyo.wlpt.cgonms.arrival.mapper") | ||
| 82 | +@EnableFeignClients | ||
| 83 | +@EnableEurekaClient | ||
| 84 | +@EnableTransactionManagement | ||
| 85 | +public class CgonmsArrivalApplication { | ||
| 86 | + public static void main(String[] args) { | ||
| 87 | + SpringApplication.run(CgonmsArrivalApplication.class, args); | ||
| 88 | + } | ||
| 89 | +} | ||
| 90 | +``` | ||
| 91 | + | ||
| 92 | +## 五、注意点 | ||
| 93 | + | ||
| 94 | +任何使用 @value 读取配置文件信息的所在类的上面,必须要添加上 @RefreshScope | ||
| 95 | + | ||
| 96 | +```java | ||
| 97 | +@RestController | ||
| 98 | +@RefreshScope | ||
| 99 | +public class IndexController { | ||
| 100 | + @Value("${server.ip}") | ||
| 101 | + private String ip; | ||
| 102 | + | ||
| 103 | + @GetMapping("/index") | ||
| 104 | + public String index(){ | ||
| 105 | + return ip; | ||
| 106 | + } | ||
| 107 | +} | ||
| 108 | +``` | ||
| 109 | + |
-
请 注册 或 登录 后发表评论