笛里谁知壮士心,沙头空照征人骨。这篇文章主要讲述#yyds干货盘点# springcloud整合eureka实现服务注册与发现相关的知识,希望能为你提供帮助。
??springcloud整合eureka实现服务注册与发现??
1.项目目录:
2.代码实现:
创建eureka父类服务,pom添加依赖
<
parent>
<
groupId>
org.springframework.boot<
/groupId>
<
artifactId>
spring-boot-starter-parent<
/artifactId>
<
version>
2.6.2<
/version>
<
relativePath/>
<
!-- lookup parent from repository -->
<
/parent>
<
groupId>
com.cxh<
/groupId>
<
artifactId>
eureka<
/artifactId>
<
version>
0.0.1-SNAPSHOT<
/version>
<
name>
eureka<
/name>
<
description>
Demo project for Spring Boot<
/description>
<
packaging>
pom<
/packaging>
<
properties>
<
java.version>
1.8<
/java.version>
<
spring-cloud-dependencies.version>
2021.0.0<
/spring-cloud-dependencies.version>
<
/properties>
<
dependencyManagement>
<
dependencies>
<
dependency>
<
groupId>
org.springframework.cloud<
/groupId>
<
artifactId>
spring-cloud-dependencies<
/artifactId>
<
version>
$spring-cloud-dependencies.version<
/version>
<
type>
pom<
/type>
<
scope>
import<
/scope>
<
/dependency>
<
/dependencies>
<
/dependencyManagement>
创建module模块eureka-server服务
添加依赖
<
parent>
<
groupId>
com.cxh<
/groupId>
<
artifactId>
eureka<
/artifactId>
<
version>
0.0.1-SNAPSHOT<
/version>
<
relativePath/>
<
!-- lookup parent from repository -->
<
/parent>
<
groupId>
com.cxh<
/groupId>
<
artifactId>
server<
/artifactId>
<
version>
0.0.1-SNAPSHOT<
/version>
<
name>
server<
/name>
<
description>
Demo project for Spring Boot<
/description>
<
properties>
<
java.version>
1.8<
/java.version>
<
/properties>
<
dependencies>
<
dependency>
<
groupId>
org.springframework.boot<
/groupId>
<
artifactId>
spring-boot-starter<
/artifactId>
<
/dependency>
<
dependency>
<
groupId>
org.springframework.boot<
/groupId>
<
artifactId>
spring-boot-starter-test<
/artifactId>
<
scope>
test<
/scope>
<
/dependency>
<
dependency>
<
groupId>
org.springframework.cloud<
/groupId>
<
artifactId>
spring-cloud-starter-eureka-server<
/artifactId>
<
version>
1.4.7.RELEASE<
/version>
<
/dependency>
<
/dependencies>
yml配置
server:
port: 8001
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:$server.port/eureka/
启动器添加注解
@EnableEurekaServer
@SpringBootApplication
public class ServerApplication
public static void main(String[] args)
SpringApplication.run(ServerApplication.class, args);
创建module模块eureka-client服务
添加依赖
<
parent>
<
groupId>
com.cxh<
/groupId>
<
artifactId>
eureka<
/artifactId>
<
version>
0.0.1-SNAPSHOT<
/version>
<
relativePath/>
<
!-- lookup parent from repository -->
<
/parent>
<
groupId>
com.cxh<
/groupId>
<
artifactId>
eureka-client<
/artifactId>
<
version>
0.0.1-SNAPSHOT<
/version>
<
name>
eureka-client<
/name>
<
description>
Demo project for Spring Boot<
/description>
<
properties>
<
java.version>
1.8<
/java.version>
<
/properties>
<
dependencies>
<
dependency>
<
groupId>
org.springframework.boot<
/groupId>
<
artifactId>
spring-boot-starter<
/artifactId>
<
/dependency>
<
dependency>
<
groupId>
org.springframework.boot<
/groupId>
<
artifactId>
spring-boot-starter-test<
/artifactId>
<
scope>
test<
/scope>
<
/dependency>
<
dependency>
<
groupId>
org.springframework.cloud<
/groupId>
<
artifactId>
spring-cloud-starter-netflix-eureka-client<
/artifactId>
<
/dependency>
<
dependency>
<
groupId>
org.springframework.boot<
/groupId>
<
artifactId>
spring-boot-starter-web<
/artifactId>
<
/dependency>
<
/dependencies>
yml配置
server:
port: 8002
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
spring:
application:
name: eureka-client
启动器添加注解
@EnableEurekaClient
@SpringBootApplication
public class EurekaClientApplication
public static void main(String[] args)
SpringApplication.run(EurekaClientApplication.class, args);
【#yyds干货盘点# springcloud整合eureka实现服务注册与发现】3.实现效果:
运行eureka-server,
eureka-client项目, 浏览器打开??http://localhost:8001/??
推荐阅读
- Golang(定时器的终止与重置)
- 高可用k8s集群搭建1.17.0
- 3516 L1 Linux版本成功启动!可以愉快地玩耍了~
- 2021年vivo互联网技术最受欢迎文章TOP25
- 跨平台技术实战!百度文库跨平台技术快速落地全过程
- #yyds干活盘点#1.2 HTML5新的Input类型
- JWT 工具类#yyds干货盘点#
- #yyds干货盘点#Spring专题「技术原理」为大家介绍一下Spring中的Ant路径匹配工具组件AntPathMatcher
- #yyds干货盘点#web安全day44(进阶!使用Nmap+Wireshark理解端口扫描)