• 欢迎光临~

搭建eureka服务注册中心,单机版

开发技术 开发技术 2022-10-18 次浏览

单独搭建的

  • 搭建springboot项目
    (1)pom文件
<?xml version="1.0" encoding="UTF-8"?>
<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>

    <groupId>org.example</groupId>
    <artifactId>eurekaServe</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>

    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR8</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

(2)yml文件

#配置注册中心1的端口,可以随意设置,不能跟其他端口冲突
server:
  port: 9889
#配置注册中心1的名字,可以随意起
spring:
  application:
    #通过查看注册中心查看有哪些模块注册进了这个注册中心
    name: eurekaServe
eureka:
  instance:
    hostname: 127.0.0.1
  client:
    # 是否向eureka注册自身服务
    register-with-eureka: false
    #是否检索服务
    fetch-registry: false
    #服务注册地址
    service-url:
      defaultZone: http://localhost:9889/eureka/

(3)启动类

package com.cgy.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

/**
 * @Author : cgy
 * @Date : 2022/10/18
 */
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class);
    }
}

启动访问:http://localhost:9899
查看服务注册中心
目录如下所示
搭建eureka服务注册中心,单机版

程序员灯塔
转载请注明原文链接:搭建eureka服务注册中心,单机版
喜欢 (0)