• 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
  • 相关阅读:
    hdu--1045--Fire Net,NYOJ--587--dfs--blockhouses
    NYOJ--1100--WAJUEJI which home strong!
    NYOJ--927--dfs--The partial sum problem
    NYOJ--1058--dfs--部分和问题
    NYOJ--491--dfs(打表水过)--幸运三角形
    素数环:NYOJ--488--dfs||hdu-1016-Prime Ring Problem
    NYOJ--353--bfs+优先队列--3D dungeon
    NYOJ--325--深度优先搜索--zb的生日
    NYOJ--284--广搜+优先队列--坦克大战
    搭建虚拟环境
  • 原文地址:https://www.cnblogs.com/mm163/p/10584355.html
Copyright © 2020-2023  润新知