加入服务端依赖

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-eureka-server</artifactId>
  4. </dependency>

配置YML

  1. server:
  2. port: 7001
  3. eureka:
  4. instance:
  5. # 使用IP注册
  6. prefer-ip-address: true
  7. hostname: localhost
  8. client:
  9. register-with-eureka: false #false表示不向注册中心注册自己
  10. fetch-registry: false #false表示自己就是注册中心,职责是维护实例,不参加检索
  11. service-url:
  12. #设置eureka server的交互地址,即对外暴露的地址
  13. defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

启动类

注意:要在类前加@EnableEurekaServer标注

  1. @SpringBootApplication
  2. @EnableEurekaServer
  3. public class EurekaApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(EurekaApplication.class,args);
  6. }
  7. }