一、引入依赖
spring-boot
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/>
</parent>
spring-cloud
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RC2</spring-cloud.version>
</properties>
dependencies中添加eureka依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
二、application.yml配置
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
-
waitTimeInMsWhenSyncEmpty
#在Eureka服务器获取不到集群里对等服务器上的实例时,需要等待的时间,单位为毫秒,默认为1000 * 60 * 5
-
registerWithEureka
实例是否在eureka服务器上注册自己的信息以供其他服务发现,默认为true
-
fetchRegistry
此客户端是否获取eureka服务器注册表上的注册信息,默认为true
三、代码
在启动类中加入注解@EnableEurekaServer
@SpringBootApplication
@EnableEurekaServer
public class LwpEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(LwpEurekaApplication.class, args);
}
}
四、启动应用
-
启动应用
-
查看eureka是否正常
显示内容,部署成功