搭建单例Eureka Server服务注册中心

服务信息

  1. 服务注册中心:cloud-eureka-server (8761)
  2. 服务提供者:service-resume (8080)
  3. 服务消费者:server-autodeliver (8090)

搭建步骤

  1. cloud-parent父工程引入Spring Cloud依赖 ```xml org.springframework.cloud spring-cloud-dependencies Greenwich.RELEASE pom import

com.sun.xml.bind jaxb-core 2.2.11

javax.xml.bind jaxb-api

com.sun.xml.bind jaxb-impl 2.2.11

org.glassfish.jaxb jaxb-runtime 2.2.10-b140310.1920

javax.activation activation 1.1.1

  1. 2. **cloud-eureka-server子工程**
  2. - pom文件引入相关依赖
  3. ```xml
  4. <dependencies>
  5. <!--Eureka server依赖-->
  6. <dependency>
  7. <groupId>org.springframework.cloud</groupId>
  8. <artifactId>spring-cloud-starter-netflix-eurekaserver</artifactId>
  9. </dependency>
  10. </dependencies>
  • application.yml配置文件

    1. #Eureka server服务端⼝
    2. server:
    3. port: 8761
    4. spring:
    5. application:
    6. name: cloud-eureka-server # 应⽤名称,会在Eureka中作为服务的id标识(serviceId)
    7. eureka:
    8. instance:
    9. hostname: localhost
    10. client:
    11. service-url: # 客户端与EurekaServer交互的地址,如果是集群,也需要写其它Server的地址
    12. defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
    13. register-with-eureka: false # ⾃⼰就是服务不需要注册⾃⼰
    14. fetch-registry: false #⾃⼰就是服务不需要从Eureka Server获取服务信息,默认为true,置为false
  • 启动类声明项目为Eureka Server

    1. @SpringBootApplication
    2. @EnableEurekaServer // 声明本项⽬是⼀个Eureka服务
    3. public class LagouCloudEurekaServerApplication {
    4. public static void main(String[] args) {
    5. SpringApplication.run(LagouCloudEurekaServerApplication.class,args);
    6. }
    7. }
  • 执行启动类,访问 http://localhost:8761, 进入Eureka注册中心后台,EurekaServer发布成功

image.png
image.png