Eureka入门
笔记
刚入门springcloud
看了【高清电子版】微服务架构基础SpringBoot+SpringCloud+Docker 被坑,做个笔记填坑
坑:使用spring-boot版本与spring-cloud依赖对不上
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
报错:
LoggingFailureAnalysisReporter - Application failed to start due to an exception
SpringApplicationBuilder.<init>([Ljava/lang/Object;)
然后自己升级了版本
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>3.0.2</version>
</dependency>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/>
</parent>
提示需要更改springboot的版本:
Change Spring Boot version to one of the following versions [2.4.x, 2.5.x]
修改SpringBoot版本为2.4.4,运行成功
学编程也不是第一次吃了版本的亏,上图

顺着做一个成功的笔记
1.创建父项目导依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
2.创建子项目导入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
3.服务端配置eureka的yml文件
server:
port: 7777
spring:
application:
name: 7777_server
# 配置eureka
eureka:
# 实例名
instance:
# 主机名
hostname: localhost
instance-id: Server_7777
# 配置clientu
client:
enabled: true
# 不需要要向自己注册
register-with-eureka: false
service-url:
defaultZone:
# http://localhost:7777/eureka/
http://${eureka.instance.hostname}:${server.port}/eureka/
4.配置服务端主类
@SpringBootApplication @EnableEurekaServer public class EurekaApplication { public static void main(String[] args) { SpringApplication.run(EurekaApplication.class,args); } }
5.客户端配置yml文件
spring: application: name: Server_7002 server: port: 7002 eureka: instance: # UP (1) - DESKTOP-MP7F61F:Server_7002:7002 prefer-ip-address: true # 使用ip地址注册 # UP (1) - user-server instance-id: user-server # 指定服务的id hostname: localhost client: register-with-eureka: true # fetch-registry: true service-url: defaultZone: http://localhost:7777/eureka/ # http://localhost:7777/eureka/
6.配置客户端主类
@SpringBootApplication @EnableEurekaClient public class ConsumerApplication { public static void main(String[] args) { SpringApplication.run(ConsumerApplication.class,args); } }
7.访问
访问Eureka页面:http://localhost:7777/
成功!

时间花在哪里,成就就在哪里

浙公网安备 33010602011771号