java 开发语言 Springboot3+cloud 2027 进行 Eureka 学习 - spring-cloud-starter-netflix-eureka-server

📅 2026-12-01 👤 拼多多助力营销技巧 📂 拼多多助力网 👁️ 151 次阅读

采用父-module 模块开发

父工程 -pom.xml

org.springframework.boot

spring-boot-dependencies

3.2.5

pom

import

​

org.springframework.cloud

spring-cloud-dependencies

2023.0.1 拼多多帮助力入口

pom

import

​

​

​

​

子模块 eureka server

pom.xml

​

org.springframework.boot

spring-boot-starter-web

​

org.springframework.cloud

spring-cloud-starter-netflix-eureka-server

​

启动类:

package com.ly;

​

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

​

@SpringBootApplication

@EnableEurekaServer

public class CloudEurekaServer7001 {

public static void main(String[] args) {

SpringApplication.run(CloudEurekaServer7001.class,args);

}

}

​

配置文件 application.yml

# 设置端口号为 7001

server:

port: 7001

​

​

eureka:

instance:

hostname: localhost

client:

fetch-registry: false #如果fetch-registry为false, 则表示自己为注册中心

register-with-eureka: false #表示是否向eureka注册中心注册自己

service-url:

defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka # 服务地址

​

​

​

​

启动测试:

子模块 eureka-provider-8001

pom.xml

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-netflix-eureka-client

org.springframework.boot

spring-boot-starter-actuator

启动类

package com.ly;

​

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

​

​

@SpringBootApplication

@EnableDiscoveryClient

public class EurekaProvider8001 {

public static void main(String[] args) {

SpringApplication.run(EurekaProvider8001.class,args);

}

}

​

application.yaml

​

#设置端口号

server:

port: 8001

​

​

​

eureka:

client:

fetch-registry: true #是提供者,不是注册中心 ,可省略

register-with-eureka: true #向注册中心 注册服务,可省略

service-url: #服务地址

defaultZone: http://localhost:7001/eureka

​

​

刷新 之前的 server

推荐链接,java

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧