SpringCloud分布式

痞子三分冷 提交于 2020-11-22 04:08:09

configServer

maven依赖

<!--spring-cloud 整合 config-server -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!--SpringCloud eureka-client -->
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

启动类

@SpringBootApplication
@EnableConfigServer
public class ServerStart {
    public static void main(String[] args) {
        SpringApplication.run(ServerStart.class,args);
    }
}

bootstrap.yml

###服务注册到eureka地址
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8100/eureka
spring:
  application:
    ####注册中心应用名称
    name: config-server
  http:
    encoding:
      charset: UTF-8
      enabled: true
      force: true
  cloud:
    config:
      server:
        git:
          ###git环境地址
          uri: https://gitee.com/SuJiaChen/SpringCloud_Config1.git
          ####搜索目录
          search-paths:
            - config
      ####读取分支
      label: master
####端口号
server:
  port: 8888

configClient

maven依赖

<!--监控中心-->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Controller类

@RestController
@RefreshScope
public class ClientController {
    @Value("${wshInfo}")
    private String name;

    @RequestMapping("getInfo")
    public String getInfo(){
        return name;
    }
}

启动类

@SpringBootApplication
@EnableEurekaClient
public class ClientStart {
    public static void main(String[] args) {
        SpringApplication.run(ClientStart.class,args);
    }
}

bootstrap.yml

spring:
  application:
    ####注册中心应用名称
    name: config-server
  cloud:
    config:
      ####读取后缀
      profile: sit
      ####读取config-server注册地址
      discovery:
        serviceId: config-server
        enabled: true
#####    eureka服务注册地址
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8700/eureka
server:
  port: 8882
##开启监控断点
management:
  endpoints:
    web:
      exposure:
        include: "*"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!