1.清空该模块的application.yml配置,并新建bootstrap.yml连接远程配置
spring: cloud: config: name: config-eureka # 仓库中的配置文件名称 label: master profile: dev uri: :33442.在pom.xml中添加spring cloud config依赖
<!--config--> <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-config --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> <version>2.1.1.RELEASE</version> </dependency>3.主启动类
@SpringBootApplication @EnableEurekaServer //EnableEurekaServer 服务端的启动类,可以接受别人注册进来~ public class ConfigEurekaServer_7001 { public static void main(String[] args) { SpringApplication.run(ConfigEurekaServer_7001.class,args); } }4.测试
第一步:启动 Config_Server_3344,并访问 :3344/master/config-eureka-dev.yml 测试
第二部:启动ConfigEurekaServer_7001,访问 :7001/ 测试
显示上图则成功
新建springcloud-config-dept-8001模块并拷贝springcloud-provider-dept-8001的内容
同理导入spring cloud config依赖、清空application.yml 、新建bootstrap.yml配置文件并配置
spring: cloud: config: name: config-dept label: master profile: dev uri: :3344主启动类
@SpringBootApplication @EnableEurekaClient //在服务启动后自动注册到Eureka中! @EnableDiscoveryClient //服务发现~ @EnableCircuitBreaker // public class ConfigDeptProvider_8001 { public static void main(String[] args) { SpringApplication.run(ConfigDeptProvider_8001.class,args); } //增加一个 Servlet @Bean public ServletRegistrationBean hystrixMetricsStreamServlet(){ ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet()); registrationBean.addUrlMappings("/actuator/hystrix.stream"); return registrationBean; } }