spring cloud配置中心

你离开我真会死。 提交于 2019-12-06 04:12:27

1.创建一个配置中心,这里我们使用码云上面的(自己创建)

2.导入包

<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-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

 

3.添加注解标签,主配置类

package cn.jiedada;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

/**
 * @EnableConfigServer:开启配置中心
 */
@SpringBootApplication
@EnableEurekaClient
@EnableConfigServer
public class EurekaConfigService5000 {
    public static void main(String[] args) {
        new SpringApplicationBuilder(EurekaConfigService5000.class).web(true).run(args);
    }
}

 

4.yml

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:1000/eureka/#注册中心地址
  instance:
    ip-address: true #使用ip配置
    instance-id: config-server #指定服务的id
server:
  port: 5000
spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/huangruijiedada/springcloud_hrm.git #路径
          username: 
          password: 

 

其他配置文件使用的方式

1.导包

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-client</artifactId>
        </dependency>

 

2.更改yml配置

 

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!