zoukankan      html  css  js  c++  java
  • spring cloud配置中心

    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配置

     把application.yml的优先级提高改为bootstrap.yml这样才可以

    spring:
      cloud:
        config:
          uri: http://localhost:5000  #这里是我们自己配置的服务器端口
          name: application-user2000 #这里是我们放在仓库中的名称application-user2000-dev.yml
          profile: dev  #这里是环境
          label: master
  • 相关阅读:
    linux & centos命令
    javascript总结
    SocanCode7之模板编写
    SocanCode连接Oracle的方法
    ashx的使用
    SocanCode代码生成器版本更新记录 [SocanCode7全新发布]
    IIS7.0中使用MVC3,静态页正常,其它404
    不用再纠结反射影响效率了
    ASP.NET MVC 框架处理请求生命周期
    create xmlhttprequest
  • 原文地址:https://www.cnblogs.com/xiaoruirui/p/11961285.html
Copyright © 2011-2022 走看看