springCloud Eureka注册中心配置详解

1、创建一个springBoot项目

2、在springBoot项目中添加SpringCloud依赖

javascript 复制代码
<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-dependencies</artifactId>
			<version>2021.0.3</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>

3、在springBoot项目中创新建一个子模块eureka-server:


4、搭建Eureka

  1. 添加依赖:在新建一个子模块的pom.xml中添加依赖
xml 复制代码
 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>3.1.3</version>
            <type>pom</type>
        </dependency>
  1. 创建配置文件:在resources文件下创建一个名为application.yml(或application.properties)的配置文件,并为Eureka Server配置必要的属性。以下是一个基本的示例配置:
yaml 复制代码
spring:
  application:
    name: eurekaServer

server:
  port: 8761

eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:8761/eureka/

1、第一个配置是为Eureka命名

2、第二个配置是设置Eureka的端口

3、第三个配置是将Eureka自己也看成是一个服务,将自己注册到Eureka中

  1. 创建启动类名为EurekaApplication:创建一个启动类并标注@EnableEurekaServer注解,以启用Eureka Server。示例代码如下:
java 复制代码
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}
  1. 启动:运行启动类

  2. 验证:通过访问http://localhost:8761(或自定义的端口)。应该能够看到Eureka Server的管理控制台,并且如果没有其他注册的服务,注册中心应该有一个eurekaserver。

这样,就成功地搭建了一个简单的Eureka Server。接下来,可以根据需要搭建Eureka Client,并将其他微服务注册到Eureka Server上。

相关推荐
mqiqe1 小时前
AgentScope Java Harness:4. 双层记忆系统 让 Agent 拥有真正的“长期大脑“
java·开发语言
伍一511 小时前
03-文件管理模块-一个看似简单的模块藏着多少细节
java·ruoyi·若依
gugucoding1 小时前
46. 【Java】JUC并发工具:让并发更简单
java·开发语言
砍材农夫1 小时前
spring-ai|Spring‑AI 2.0.0 新特性 + 入门教程
spring boot·spring·spring cloud
Nebula_g2 小时前
JavaSE基础语法:面向对象高级(代码中的成分)
java·开发语言·编程·javase·技术栈·高级语法
AC赳赳老秦2 小时前
公开图片 OCR 数据提取:OpenClaw 合规采集公开信息图,识别文字与表格并转化为结构化数据
java·大数据·前端·数据库·python·php·openclaw
小强库计算机毕业设计4 小时前
SpringBoot+Vue3 学生宿舍管理系统实战
java·spring boot·后端·vue·学生宿舍管理系统
李冰然4 小时前
深入Java集合框架:HashMap源码解析(JDK 8)
java
人道领域5 小时前
【0-1的agent进阶篇】RAG:从Embedding到检索增强生成的底层逻辑
java·embedding·agent·rag
桦说编程5 小时前
盘点并发集合里那些容易误判的行为
java·后端·性能优化