Eureka服务注册与发现
一、Eureka基础知识
服务治理服务注册Eureka两组件 二、单机Eureka构建步骤
1、IDEA生成eurekaServer端服务注册中心
Eureka服务注册与发现 一、Eureka基础知识 服务治理 服务注册
建module
cloud-eureka-server7001
改pom
server端依赖对比:
在pom中添加依赖
org.springframework.cloud spring-cloud-starter-netflix-eureka-server com.atyy.springcloud cloud-api-commons ${project.version} org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test
- 写yml
在resources目录下新建application.yml文件
server:
port: 7001
eureka:
instance:
hostname: localhost #eureka服务端的实例名称
client:
#false表示不向注册中心注册自己(想注册也可以,不过没必要)
register-with-eureka: false
#false表示自己端就是注册中心,职责就是维护服务实例,并不需要去检索服务
fetch-registry: false
service-url:
#设置与eurekaServer交互的地址查询服务和注册服务都需要依赖这个地址
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
- 主启动
在java包下新建com.angenin.springcloud.EurekaMain7001
@SpringBootApplication
@EnableEurekaServer //表示EurekaMain7001是Eureka的服务注册中心
public class EurekaMain7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaMain7001.class,args);
}
}
- 测试



