• (七)SpringCloud学习系列-Eureka服务注册与发现(2)


    转载:https://www.cnblogs.com/XiangHuiBlog/p/12089755.html

    构建 microservicecloud-eureka-7001 eureka服务注册中心Module

    1.新建microservicecloud-eureka-7001

    2.pom

    复制代码
    <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.atguigu.springcloud</groupId>
       <artifactId>microservicecloud</artifactId>
       <version>0.0.1-SNAPSHOT</version>
      </parent>
     
      <artifactId>microservicecloud-eureka-7001</artifactId>
     
      <dependencies>
       <!--eureka-server服务端 -->
       <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-eureka-server</artifactId>
       </dependency>
       <!-- 修改后立即生效,热部署 -->
       <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>springloaded</artifactId>
       </dependency>
       <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-devtools</artifactId>
       </dependency>
      </dependencies>
     
    </project>
    复制代码

    3.yml

    复制代码
     
    server: 
      port: 7001
     
    eureka:
      instance:
        hostname: localhost #eureka服务端的实例名称
      client:
        register-with-eureka: false #false表示不向注册中心注册自己。
        fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
        service-url:
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/        #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址。
     
    复制代码

    4.EurekaServer7001_App主启动类

    复制代码
    package com.atguigu.springcloud;
     
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
     
    @SpringBootApplication
    @EnableEurekaServer//EurekaServer服务器端启动类,接受其它微服务注册进来
    public class EurekaServer7001_App
    {
      public static void main(String[] args)
      {
       SpringApplication.run(EurekaServer7001_App.class, args);
      }
    }
     
     
    复制代码

    5.测试

    先要启动EurekaServer

    http://localhost:7001/

  • 相关阅读:
    Linux常见问题解决
    (转)CoreDNS:Kubernetes内部域名解析原理、弊端及优化方式
    (转)Go sync.WaitGroup的用法
    (转)5个维度对 Kubernetes 集群优化及压测方案
    使用 Alpine 作为基础镜像时可能会遇到的常见问题的解决方法
    提前预防K8s集群资源不足的处理方式配置
    docker runc升级
    Nginx常见问题解决
    DNS泛域名解析应用(nip.io)
    使用Velero备份Kubernetes集群
  • 原文地址:https://www.cnblogs.com/cjh184/p/12787144.html
Copyright © 2020-2023  润新知