教你一步一步搭建搭建eureka注册中心服务

2021/4/27 18:27:29

本文主要是介绍教你一步一步搭建搭建eureka注册中心服务,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

搭建eureka服务

  • 第一步:创建maven项目 pom.xml
  • 第二部:配置application.yml
  • 第三部:主启动类加@EnableEurekaServer注解

第一步:创建maven项目 pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <groupId>com.example</groupId>
    <artifactId>register-eureka-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>register-eureka-test</name>
    <description>Demo project for Spring Boot</description>
    
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>2020.0.2</spring-cloud.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</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>

第二部:配置application.yml

server:
  port: 8761

spring:
  application:
    name: eureka-register-center-test

eureka:
  instance:
    hostname: 127.0.0.1
  client:
    fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
    register-with-eureka: false #false表示不向注册中心注册自己。
  serviceUrl:
    defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

第三部:主启动类加@EnableEurekaServer注解

@EnableEurekaServer //开启eureka注册中心
@SpringBootApplication
public class RegisterEurekaTestApplication {

    public static void main(String[] args) {
        SpringApplication.run(RegisterEurekaTestApplication.class, args);
    }

}


这篇关于教你一步一步搭建搭建eureka注册中心服务的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程