-
pom.xml引入jar包
<!--eureka-client --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
-
application.yml添加Eureka相关配置
eureka: instance: instance-id: ${spring.application.name} #注册的这个服务的名字 client: fetch-registry: true # 从服务端获取注册的服务信息 register-with-eureka: true #将自己注册到注册中心 service-url: defaultZone: http://localhost:8300/eureka/ #Eureka地址
-
主启动类EurekaServer8300.java
@SpringBootApplication @EnableEurekaClient //@EnableEurekaClient只适用于Eureka作为注册中心,@EnableDiscoveryClient 可以是其他注册中心。 public class EurekaServer8300 { public static void main(String[] args){ SpringApplication.run(EurekaServer8100.class, args); } }