zoukankan      html  css  js  c++  java
  • 4.2 SpringCloud__服务注册与发现Eureka__搭建注册中心

    SpringCloud__服务注册与发现Eureka__搭建注册中心

    搭建Eureka服务注册中心

    前面说过eureka是c/s模式的  server服务端就是服务注册中心,其他的都是client客户端,服务端用来管理所有服务,客户端通过注册中心,来调用具体的服务;

    我们先来搭建下服务端,也就是服务注册中心;

    新建 module   microservice-eureka-server-2001

    <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.java1234.springcloud</groupId>
        <artifactId>microservice</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </parent>
      <artifactId>microservice-eureka-server-2001</artifactId>
       
      <dependencies>
             <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>

    主要是加入eureka-server依赖;

    application.yml配置:

    server:
      port: 2001
      context-path: /
      
    eureka: 
      instance:
        hostname: localhost #eureka注册中心实例名称
      client: 
        register-with-eureka: false     #false 由于该应用为注册中心,所以设置为false,代表不向注册中心注册自己。
        fetch-registry: false     #false 由于注册中心的职责就是维护服务实例,它并不需要去检索服务,所以也设置为false
        service-url: 
           defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/       #设置与Eureka注册中心交互的地址,查询服务和注册服务用到

    启动类:

    package com.java1234;
     
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
     
    @SpringBootApplication
    @EnableEurekaServer
    public class EurekaApplication_2001 {
     
        public static void main(String[] args) {
            SpringApplication.run(EurekaApplication_2001.class, args);
        }
    }

    主要是要加入下@EnableEurekaServer

    测试:

    运行:http://localhost:2001/

  • 相关阅读:
    【转】HTML CANVAS
    【转】JY 博客
    【转发】如何使用NPM?CNPM又是什么?
    【转廖大神】package.json 包安装
    【转】Socket接收字节缓冲区
    C# 串口操作系列(5)--通讯库雏形
    C# 串口操作系列(3) -- 协议篇,二进制协议数据解析
    C# 串口操作系列(4) -- 协议篇,文本协议数据解析
    .netCore微服务使用Nginx集中式管理实现
    nginx代理访问及上传文件异常413 Request Entity Too Large
  • 原文地址:https://www.cnblogs.com/cbpm-wuhq/p/15383221.html
Copyright © 2011-2022 走看看