1、构建步骤
1)eureka-server
(1)创建Meven工程
springcloud-eureka-7001
(2)导jar包
使用
spring-cloud-starter-netflix-eureka-server
<!-- spring-cloud-starter-eureka-server:已废弃 -->
<!-- spring-cloud-starter-netflix-eureka-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
(3)application.yml
server:
port: 7001
# Eureka配置
eureka:
instance:
# Eureka服务端的实例名字
hostname: localhost
client:
# 表示是否向 Eureka 注册中心注册自己 (这个模块本身是服务器,所以不需要)
register-with-eureka: false
# fetch-registry 是否拉取其他的服务;如果为 false,则表示自己为注册中心或服务提供者;服务消费者的话为 true
fetch-registry: false
# Eureka监控页面~
service-url:
defaultZone: http://${
eureka.instance.hostname}:${
server.port}/eureka/
register-with-eureka
是否注册到eureka服务中;默认为true
fetch-registry
是否拉取其他的服务;默认为true
- 监控地址:
http://localhost:7001/
- 服务注册地址:
http://localhost:7001/eureka/
(4)主启动类
@EnableEurekaServer
开启 Eureka 服务端
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer_7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaServer_7001.class,args);
}