2022-08-23 14:02

eureka配置步骤

陈雷

项目

(532)

(0)

收藏

首先创建工程配置pom文件导入依赖

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

其次配置application.yml或者application.properties

server:
  port: 9000
#配置eureka
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false #是否将自己注册到注册中心
    fetch-registry: false  #是否要从eureka中获取注册信息
    #配置暴露给eureka Client的请求地址
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

最后配置启动类 

在启动类上加一个注解

@EnableEurekaServer

激活eureka server


配置完之后将服务提供者注册到eureka Server上

一、引入EurekaClient的坐标

在需要引入坐标的pom文件加入依赖


  1. <!--引入eurekaClient -->
    <dependency>
       <groupId>org.springframework.cloud</groupId>
       <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
  2. 在application.yml当中添加
    #配置Eureka
    eureka:
      client:
        service-url:
          defaultZone: http://localhost:9000/eureka/
      instance:
        prefer-ip-address: true #使用ip地址注册
  3. 然后在该启动类添加注解

    image.png



  4. @EnableEurekaClient和@EnableDiscoveryClient都可以 @EnableDiscoveryClient是spring提供的一个注解 他包含第一个

    在新版本当中 这俩注解不写也可以 如果你配置好了之后 他会自动把信息注册上去

    最后重启启动类 然后你会在注册中心看到已经注册的

    image.png

调用image.png

0条评论

点击登录参与评论