• springcloud(6)-配置服务器


    1.创建config-server

    image-20201116105906570

    2.pom.xml配置

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.zhangdemo</groupId>
        <artifactId>springcloud</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </parent>
      <artifactId>configServer</artifactId>
    
      <dependencies>
        <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>
    
      </dependencies>
    </project>
    

    3.ConfigServerApplication加入@EnableConfigServer

    package com.zhangdemo;
    
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    import org.springframework.cloud.config.server.EnableConfigServer;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    
    import cn.hutool.core.util.NetUtil;
    
    @SpringBootApplication
    @EnableConfigServer
    @EnableDiscoveryClient
    @EnableEurekaClient
    public class ConfigServerApplication {
        public static void main(String[] args) {
            int port = 8030;
            if(!NetUtil.isUsableLocalPort(port)) {
                System.err.printf("端口%d被占用了,无法启动%n", port );
                System.exit(1);
            }
            new SpringApplicationBuilder(ConfigServerApplication.class).properties("server.port=" + port).run(args);
    
        }
    }
    

    4.application.yml

    spring:
      application:
        name: config-server
      cloud:
        config:
          server:
            git:
              uri: https://github.com/zhangkaixing/springcloudConfig
              searchPaths: respo
              default-label: main
    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
    

    5.测试http://localhost:8030/version/dev

    image-20201116110414946

    ps.出现的问题:

    1.仓库编程main了,需要修改配置文件

    仓库
  • 相关阅读:
    字符串与Json操作
    默认让IE用最高文档模式浏览网页
    MVC中简单的文件下载代码
    2017年1月22日
    JDK环境变量设置
    如何实现windows命令提示符的tab补全
    win7热点设置
    为什么小米5不能适配win7
    各种错误锦集
    插头DP
  • 原文地址:https://www.cnblogs.com/NaoDaiYouDianDa/p/13985354.html
Copyright © 2020-2023  润新知