【Spring Cloud Finchley.SR + Spring Boot 2.0.6】 Bus

本文源碼:https://github.com/Darren0415/Spring-Cloud(有什麼問題可以提issue給我,一起學習,共同進步。)

1、Config Server

1.1、maven配置

1.2、啓動類:

1.3、配置類

坑一:

必須去掉formLogin(),否則spring security無法認證,報401。

源碼:

org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.class:164

1.4、基本配置

1.5、config server配置(需要安裝Rabbit MQ

ERLang下載:http://www.erlang.org/downloads
RabbitMQ下載:http://www.rabbitmq.com/#support  (需要先安裝erlang(語言))
管理界面安裝:http://www.rabbitmq.com/management.html
rabbitmq-plugins enable rabbitmq_management


管理界面地址:http://localhost:15672/
帳號密碼:guest guest

坑二:

必須手動開啓refresh、bus-refresh端點,通過management.dendpints.web.exposure.incluede(此處是開啓所有)

1.6、banner配置(自己喜歡就好)

1.7、logback-spring配置(自己喜歡就好)

2、Config Client

2.1、maven配置

2.2、啓動類配置

2.3、Controller配置(加上註解@RefreshScope

2.4、config client配置

坑三:

使用service-id來配置config client時,將base config放入application.yml中無法獲取配置,需要放入bootstrap.yml中。

使用uri配置是OK的。。。

使用uri來配置:

2.5、Mybatis配置

3、Git

https://gitee.com/mycode2018/darren-micro-config

Mybatis配置:

基本配置(本來這些配置是放在application.yml中的,後面使用service-id無法獲取,詳情見坑三):

4、測試

4.1、訪問http://localhost:7771/test查看test的值

4.2、修改Git配置文件

4.3、通過postmen刷新配置(坑一:返回碼是401

http://localhost:8764/actuator/bus-refresh:此鏈接是刷新所有client配置

4.4、查看刷新結果

5、配置webhooks

作用:git提交時,請求http://localhost:8764/actuator/bus-refresh刷新配置(地址必須是域名哦。。。)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章