Eureka注册中心单点模式

Eureka注册中心单点模式搭建步骤

  1. 新建pom工程,引入spring cloud 及eureka-server 相关依赖。具体版本参见官网。本例pom如下:

    <dependencies>
        <!-- spring cloud version -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Hoxton.SR5</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- spring boot version -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.3.3.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
    
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>`
    
  2. 配置properties/yaml文件

#服务端口
server.port=7001

#服务名
spring.application.name=eureka-server

#设置请求编码
server.servlet.encoding.enabled=true
server.servlet.encoding.charset=UTF-8
server.servlet.encoding.force-request=true

#自我保护
eureka.server.enable-self-preservation=false
#取消自我服务注册
#eureka.client.register-with-eureka=false
#禁止拉取注册服务列表
#eureka.client.fetch-registry=false
#服务名:优先取该值,否则同spring.application.name设置值
#eureka.instance.appname=eureka-server-app
#默认值为false。值为false:以主机名向服务中心注册;值为true:以ip向服务中心注册
eureka.instance.prefer-ip-address=true
#服务注册中心地址
eureka.client.service-url.defaultZone=http://localhost:7001/eureka/

3.写启动类

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

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerMain7001 {

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

}
  1. 启动服务,浏览器请求:http://localhost:7001
    在这里插入图片描述

代码地址:https://github.com/zianiacumt/spring-cloud.git

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值