01 | 搭建Eureka客户端
1.1 依赖相关jar
<!-- 引入eureka客户端端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--依赖web应用-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--使用undertow作为web容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
1.2 配置注册中心链接
eureka:
client:
serviceUrl:
defaultZone: http://localhost:9081/eureka/
fetchRegistry: true
instance:
instanceId: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
preferIpAddress: true
1.3 源码分析入口
Eureka客户端的入口与服务端的入口基本一致,都是找到对应项目下的spring.factories文件,找到对应的自动配置类,Eureka客户端的的自动配置为EurekaClientAutoConfiguration