zoukankan      html  css  js  c++  java
  • (七)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/

  • 相关阅读:
    ORACLE通过netca配置监听遇到 TNS04415错误
    图说计算机编程简史
    关于在VS2008以下版本的MFC程序使用VS 2008 FeaturePack出现内存泄露的理解
    对话框的OnPaint函数的两种写法的区别
    Hibernate 3.6.0 Beta1
    Hibernate 3.6.0 Beta1
    Maven 与 Checkstyle
    NetBeans 时事通讯(刊号 # 110 Jul 21, 2010)
    NetBeans 时事通讯(刊号 # 111 Jul 28, 2010)
    教育哲学的碰撞
  • 原文地址:https://www.cnblogs.com/cjh184/p/12787144.html
Copyright © 2011-2022 走看看