详细参考:《Sprin Cloud 与 Docker 微服务架构实战》p162-9.9.4节
要做的改动是:
1、在spring cloud config server 服务端加入 spring-cloud-starter-bus-amqp 包
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.thunisoft</groupId>
<artifactId>thunisoft-microservice-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>thunisoft-microservice-config</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.SR2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2、添加配置
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
spring:
application:
name: thunisoft-microservice-configs
cloud:
config:
server:
git:
uri: https://gitee.com/ultrastrong/spring-cloud-config
clone-on-start: true # 启动时候就clone配置仓库
default-application-name: thunisoft-microservice-foo
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
server:
port: 8979
# 默认关闭权限验证
management:
security:
enabled: false
不要忘记关闭服务器端的安全认证,否则无法访问到端点。
3、使用 /bus/refresh 端点刷新配置时,只要在 服务器端就行了,这样所有的端点就都能收到更新请求了。
http://localhost:8979/bus/refresh
来源:oschina
链接:https://my.oschina.net/u/4397864/blog/4046347