加入服务端依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
配置YML
server:
port: 7001
eureka:
instance:
# 使用IP注册
prefer-ip-address: true
hostname: localhost
client:
register-with-eureka: false #false表示不向注册中心注册自己
fetch-registry: false #false表示自己就是注册中心,职责是维护实例,不参加检索
service-url:
#设置eureka server的交互地址,即对外暴露的地址
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
启动类
注意:要在类前加@EnableEurekaServer标注
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class,args);
}
}