<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository -->
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
server: port: 8000 #spring cloud config native spring: profiles: active: native application: name: config-server-eureka cloud: config: server: native: search-locations: /home/smile/workspace-sts/config-repo #spring cloud config git #spring: # application: # name: config-server-eureka # cloud: # config: # server: # git: # uri: http://localhost:3380/root/smile.git # search-paths: config-repo # username: root # password: root123456 eureka: client: service-url: defaultZone: http://localhost:8761/eureka/ ## actuator refresh management: # server: # port: 8003 endpoint: refresh: enabled: true endpoints: web: exposure: include: ‘*‘ # - info # - health # - refresh # include: ‘*‘ 开启所有接口。包含用到的 /actuator/bus-refresh
pplication.properties
## 开启消息跟踪 spring.cloud.bus.trace.enabled=true ##rabbimq spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest spring.devtools.add-properties=false
package com.smile; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient @EnableConfigServer public class ConfigServerEurekaBusRabbitmqApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerEurekaBusRabbitmqApplication.class, args); } }
visit: http://localhost:8000/smile/config-dev
refresh :
post: localhost:8000/actuator/bus-refresh
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</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-web</artifactId> </dependency>
server: port: 8003 spring: application: name: config-client-eureka cloud: config: # uri: http://localhost:8000/ discovery: enabled: true service-id: config-server-eureka name: smile profile: config-dev # dev 开发环境配置文件 | test 测试环境 | pro 正式环境 smile-config-dev.properties {name}-{profile}.properties bus: trace: enabled: true rabbitmq: host: localhost port: 5672 username: guest password: guest eureka: client: # registerWithEureka: false # fetchRegistry: false serviceUrl: defaultZone: http://localhost:8761/eureka/ management: endpoint: refresh: enabled: true # endpoints: # web: # exposure: # include: ‘*‘ #此处不再需要手动刷新
package com.smile; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient public class ConfigClientEurekaBusRabbitmqApplication { public static void main(String[] args) { SpringApplication.run(ConfigClientEurekaBusRabbitmqApplication.class, args); } }
package com.smile.controller; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RefreshScope public class ConfigClientController { @Value("${name}") String name; @Value("${age}") String age; @RequestMapping("/hello") public String hello() { return "name:"+name+",age:"+age; } }
test
update smile-config-dev.properties age=23-->age=24
post http://localhost:8000/actuator/bus-refresh with firefox
visit http://localhost:8003/hello/ this age is 24
spring cloud:config-eureka-refresh-bus-rabbitmq
原文:https://www.cnblogs.com/alittlesmile/p/10893610.html