zoukankan      html  css  js  c++  java
  • Spring cloud(2)B Eureka 注册微服务到服务中心

    1.在provide上添加pom(必须加上web)   如果不加 启动后就会自己关闭

          <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
                <version>2.1.1.RELEASE</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-config</artifactId>
                <version>2.1.1.RELEASE</version>
            </dependency>
        <dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.5</version>
    </dependency>

        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
          <version>2.1.3.RELEASE</version>
        </dependency>

    2. yml配置

    server:
      port: 8001
    
    eureka:
      client:     #客户端注册进eureka服务列表内
        service-url:
          defaultZone: http://localhost:7001/eureka

    3. 启动类

    package com.service;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    
    @SpringBootApplication
    @EnableEurekaClient
    public class Eureka_Service {
        public static void main(String[] args){
            SpringApplication.run(Eureka_Service.class,args);
        }
    }

     4. 修改主机映射名称

    instance:
        instance-id: mmdept123

    完整

    eureka:
      client:     #客户端注册进eureka服务列表内
        service-url:
          defaultZone: http://localhost:7001/eureka
      instance:
        instance-id: mmdept123  #设置主机映射名称

     5.修改ip

     prefer-ip-address: true

    完整

    server:
      port: 8001
    
    eureka:
      client:     #客户端注册进eureka服务列表内
        service-url:
          defaultZone: http://localhost:7001/eureka
      instance:
        instance-id: mmdept123
        prefer-ip-address: true
    
    spring:
      application:
        name: mm_dept

    对比

    #eureka01的配置信息
    spring:
      application:
        name: eureka #spring应用名称我这里都使用的是eureka
    server:
      port: 7001 #应用端口
    
    eureka:
      instance:
        hostname: localhost #域名  可以修改hosts文件做域名映射
        prefer-ip-address: false #如果开启了此配置会导致集群不可用 (关闭或者不配置)
        instance-id: eureka
      client:
        register-with-eureka: false #是否要将自己注册进去
        fetch-registry: false #是否要被检索
        #eureka的访问路径,集群节点寻找时的地址信息,只需要配置其他两个节点的信息
        service-url:
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
      server:
        eviction-interval-timer-in-ms: 30000 # 每隔30秒进行一次服务列表清理

    6.完善info

    provide添加pom

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-actuator</artifactId>
        <version>2.1.3.RELEASE</version>
    </dependency>

    总pom

    <finalName>dept</finalName>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
          </resource>
        </resources>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
              <delimiters>
                <delimiter>$</delimiter>
              </delimiters>
            </configuration>
          </plugin>
        </plugins>

    8001的application.yml中添加

    info:
      app.name: mm123
  • 相关阅读:
    [转贴]ASP.NET下对远程SQL SERVER数据库的备份和恢复的存储过程
    [原创]一个不错TreeView的样式
    [转贴]如何在ASP.NET中用OWC绘制图表
    [讨论]如何提高博客的访问量,写什么样的文章比较吸引读者啊!
    Revit API电缆桥架CableTray
    黄聪:win7系统下麦克风无法使用、有杂音和电流声的解决办法
    黄聪:.Net Framework Initialization Error – Unable to find a version of the runtime to run this application解决方案
    黄聪:js、Jquery将日期例如(20120903)转换为数字格式
    黄聪:wordpress文章同步发布到网易、天涯、新浪博客、百度空间插件
    黄聪:WIN7下安装 virtualbox WIN7系统 无法安装增强功能
  • 原文地址:https://www.cnblogs.com/mm163/p/10584355.html
Copyright © 2011-2022 走看看