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);
        }
    }
  • 相关阅读:
    flask插件系列之flask_cors跨域请求
    【电脑蓝屏记】
    .net 定时启动任务
    c# winform+wcf代理上网的处理
    WCF
    Sql Over的用法
    【转】c#的逆向工程-IL指令集
    【随记】代码混编的重要性
    【转】android学习日记01--综述
    c#获取网页代码、数据、资源
  • 原文地址:https://www.cnblogs.com/mm163/p/10584228.html
Copyright © 2011-2022 走看看