pom:
4.0.0 com.toov5 SpringCloud-eureka-server 0.0.1-SNAPSHOT org.springframework.boot spring-boot-starter-parent 2.0.1.RELEASE org.springframework.cloud spring-cloud-dependencies Finchley.M7 pom import org.springframework.cloud spring-cloud-starter-netflix-eureka-server spring-milestones Spring Milestones https://repo.spring.io/libs-milestone false
yml:
###eureka 服务端口号server: port: 8100###服务注册名称eureka: instance: ##注册中心ip地址 hostname: 127.0.0.1###客户端调用地址 client: serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/###因为该应用为注册中心,不会注册自己 (集群设为true) register-with-eureka: false###因为自己为注册中心 ,不会去在该应用中的检测服务 fetch-registry: false
Eureka:
package com.toov5;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@EnableEurekaServer //开启注册中心@SpringBootApplication public class AppEureka { public static void main(String[] args) { SpringApplication.run(AppEureka.class, args); } }
目录结构:
启动后的访问: