一、新建多个eureka服务的spring boot项目
需要引入的依赖启动器
yml文件配置
eureka:
instance:
hostname: localhost
prefer-ip-address: true
client:
register-with-eureka: true
fetch-registry: false
service-url: #单个eureka服务配置
#defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
#搭建集群,关联其他eureka服务
defaultZone: http://localhost:8003/eureka/,http://localhost:8004/eureka/
启动类新增开启的注解
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer //eureka服务,接收服务注册
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class,args);
}
}
启动即可看到集群信息的内容!