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上。

相关推荐
小科先生44 分钟前
Java springboot调用数据库的基本流程
java·数据库·spring boot
秋饼2 小时前
GPT-Live 全双工语音 API Java 服务端落地实战:事件协议、会话恢复与生产踩坑
java·ai·技术分享·后端开发
SL_staff2 小时前
为什么企业级自动化不能只靠AI编排?——逻辑引擎在确定性业务场景中的不可替代性
java·开源·产品
Pniubi3 小时前
MySQL靠什么实现事务的?事务隔离级别有哪些?
java·数据库·mysql
松仔log4 小时前
Kotlin中级——callbackFlow
java·前端·kotlin
知守观4 小时前
同一个团队两套分包:DDD 四层落地后,domain 层最大的类还是 5885 行
java·后端·领域驱动设计
文丑颜不良啊5 小时前
LeetCode2541~2560题目解析
java·leetcode
瑞雪兆丰年兮5 小时前
JavaWeb-day11-SpringBootWeb案例(文件上传)
java·运维·服务器·javaweb·oss
Highcharts.js5 小时前
Highcharts智能数据分析平台Orbit 多语言配置技术文档
java·前端·javascript·highcharts·orbit·智能数据分析·设置文档
Rain的Java大神之路5 小时前
设计一套生产级 API 接口:从契约、安全、幂等到限流,我踩过的坑都在这了
java·后端·面试