本文共 4140 字,大约阅读时间需要 13 分钟。
pom.xml
4.0.0 com.xiaobu springcloud-demo 0.0.1-SNAPSHOT com.xiaonbu config-bus 0.0.1-SNAPSHOT config-bus config-bus project for Spring Boot 1.8 org.springframework.cloud spring-cloud-starter-config org.springframework.boot spring-boot-starter org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.cloud spring-cloud-starter-bus-amqp org.springframework.boot spring-boot-starter-actuator org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import org.springframework.boot spring-boot-maven-plugin
bootstrap.properties
# 从config-server获取配置信息#server.port=7002#{application}#spring.application.name=xiaobu#{profile}#spring.cloud.config.profile=dev#{label}#spring.cloud.config.label=master# spring.cloud.config.uri=http://localhost:7001/# 从eureka-server获取配置信息#{application}spring.application.name=xiaobu#{profile}spring.cloud.config.profile=dev#{label}spring.cloud.config.label=masterspring.cloud.config.uri=http://localhost:7001/eureka.client.serviceUrl.defaultZone=http://localhost:8001/eureka/spring.cloud.config.discovery.enabled=truespring.cloud.config.discovery.serviceId=config-serverserver.port=7003
ConfigBusApplication
package com.xiaonbu;import lombok.extern.slf4j.Slf4j;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.CommandLineRunner;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.context.config.annotation.RefreshScope;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication@EnableEurekaClient@EnableDiscoveryClient@RestController@RefreshScope@Slf4jpublic class ConfigBusApplication implements CommandLineRunner { public static void main(String[] args) { SpringApplication.run(ConfigBusApplication.class, args); } @Value("${server.port}") private String port; @Override public void run(String... args) throws Exception { log.info("config-client 在端口{}启动成功", port); } @Value("${from}") String from; @GetMapping("/from") public String from() { return from; }}
依次启动 eureka-server config-server config-bus
访问http://localhost:8001/
访问 http://localhost:7003/from
git-dev-1.0 QAQ
修改代码仓库的文件内容 from=git-dev-1.0 hasagei!
先post一下 http://localhost:7003/actuator/bus-refresh
然后先前是G版本的 无论怎么post都不行,后面查资料才知道Greenwich.M1版本的bus总线/actuactor/bus-refresh时发生问题。
所以改成了H版本 一下就成功了。
org.springframework.boot spring-boot-starter-parent 2.2.0.RELEASE UTF-8 UTF-8 1.8 Hoxton.RELEASE
再访问 http://localhost:7003/from 出现
git-dev-1.0 hasagei!
转载地址:http://wkgai.baihongyu.com/