zoukankan      html  css  js  c++  java
  • Spring Cloud(2)A Eureka server端 服务注册建立

    1. 父项目pom

     1    <dependency>
     2       <groupId>org.springframework.cloud</groupId>
     3       <artifactId>spring-cloud-dependencies</artifactId>
     4       <version>Greenwich.RELEASE</version>
     5       <type>pom</type>
     6     </dependency>

    10 <dependency> 11 <groupId>org.springframework.boot</groupId> 12 <artifactId>spring-boot-dependencies</artifactId> 13 <version>2.1.3.RELEASE</version> 14 <type>pom</type> 15 <scope>provided</scope> 16 </dependency>

    2.Eureka pom

     1        <dependencies>
     2         <dependency>
     3             <groupId>com.google.code.gson</groupId>
     4             <artifactId>gson</artifactId>
     5             <version>2.8.5</version>
     6         </dependency>
     7 
     8         <dependency>
     9             <groupId>org.springframework.cloud</groupId>
    10             <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    11             <version>2.1.0.RELEASE</version>
    12         </dependency>    
    13         
    14         <dependency>
    15             <groupId>junit</groupId>
    16             <artifactId>junit</artifactId>
    17             <version>4.11</version>
    18             <scope>test</scope>
    19         </dependency>

    3. yml 配置

    server:
      port: 7001
    
    eureka:
      instance:
        hostname: localhost  #eureka服务器的实例名称
      client:
        register-with-eureka: false  #表示不想注册中心注册自己
        fetch-registry: false  #表示自己就是注册中心
        service-url:
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/    #设置与eureka server交互的地址查询服务

    客户端向服务端每30s 发送一次心跳,90s 之后客户端如果没有发送心跳,Service 会去除这个客户端

    4.启动类

    package com.service;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    
    @SpringBootApplication
    @EnableEurekaServer  //服务器启动类,接受其他微服务注册进来
    public class Dept_Eureka {
    
        public static void main(String[] args){
            SpringApplication.run(Dept_Eureka.class,args);
        }
    }
  • 相关阅读:
    ASP.NET MVC 入门9、Action Filter 与 内置的Filter实现(介绍) 【转】
    一个建议,看看大家的意见。
    发现不错的文章,推!
    有个小问题,大家一起研究。
    逼不得已,这个我确实不会,昨办?
    MSN Message6.2 的小BUG
    在IE7浏览器中切换成以资源管理器方式
    手机罗盘(指南针)校准方法
    G13/ Wildfire S/A510e link2SD教程,干净清洁的安装程序到内存卡
    HTC G13电池怎么鉴别真伪
  • 原文地址:https://www.cnblogs.com/mm163/p/10584228.html
Copyright © 2011-2022 走看看