使⽤Spring Cloud Netflix 中的 Eureka 搭建服务注册与发现中⼼
创建SpringBoot应⽤,添加依赖
spring web
eureka server
配置服务注册与发现中心
## 设置服务注册与发现中⼼的端⼝
server:
port: 8761
## 在微服务架构中,服务注册中⼼是通过服务应⽤的名称来区分每个服务的
## 我们在创建每个服务之后,指定当前服务的 应⽤名/项⽬名
spring:
application:
name: service-eureka
eureka:
client:
## ip 就是服务注册中⼼服务器的ip
## port 就是服务注册与发现中⼼设置的port
service-url:
defaultZone: http://192.168.54.59:8761/eureka
## 设置服务注册与发现中⼼是否为为集群搭建(如果为集群模式,多个eureka节点之间
需要相互注册)
register-with-eureka: false
## 设置服务注册与发现中是否作为服务进⾏注册
fetch-registry: false
在启动类添加@EnableEurekaServer注解
@SpringBootApplication
@EnableEurekaServer
public class ServiceEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceEurekaApplication.class, args);
}
}
运行及访问