【转载】Eureka实现单服务中心(线上必须多个)

参考

  1. spring cloud 实战派

步骤

  1. 通过阿里云快速生成springboot项目。(idea也可以以相同方式创建)

  2. 选择 2.3.5版本的springboot,或者选择你需要的版本
    image

  3. 在高级选项中选择 jdk版本为 11,或者选择你需要的版本
    image

  4. 使用idea导入项目.

  5. 在入口文件类添加注解(我的项目起名为 eureka_server_demo ,你的名字可能和我设置的不同,所以我们包路径以及启动类名字不同)

package com.example.eureka_server_demo;

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

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerDemoApplication {

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

}

  1. 在配置文件 application.properties 内编写以下配置
# 应用名称
spring.application.name=Eureka Server Demo
# 端口号
server.port=8080
# 是否注册到 eureka server
eureka.client.register-with-eureka=true
# 是否 eureka 获取注册信息
eureka.client.fetch-registry=true
# 设置查询服务和注册服务与 eureka server 交互地址,多个地址可用 ',' 分隔,${server.port} 代表引用当前配置文件内的变量,也就是 8080
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
  1. 点击运行并访问 http://localhost:8080/ ,显示 控制台

image

注意事项

  1. 一定到记得在入口文件添加 @EnableEurekaServer 注解
  2. 配置文件检查拼写错误
posted @   夏秋初  阅读(60)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示