测试环境 - SpringBoot + Eureka环境搭建

Eureka环境搭建

  1. 下载镜像

    docker pull springcloud/eureka
    

  2. 运行镜像

    docker run -dit --name eureka -p 8080:8761  springcloud/eureka:latest
    

  3. 查看网页

IDEA搭建SpringBootgong工程

  1. 新建Spring Boot工程

  2. 修改pom文件
    1)调整版本为2.0.1.RELEASE

     <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
         <version>2.0.1.RELEASE</version>
         <relativePath/> <!-- lookup parent from repository -->
     </parent>
    

    2)添加Cloud的相关依赖

    <dependencyManagement>
         <dependencies>
             <dependency>
                 <groupId>org.springframework.cloud</groupId>
                 <artifactId>spring-cloud-dependencies</artifactId>
                 <version>Finchley.SR1</version>
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
         </dependencies>
     </dependencyManagement>
    

    3)增加相关依赖

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

    4)修改项目配置文件,增加eureka相关配置

    spring:
      application:
        name: omm
    eureka:
      client:
        registerWithEureka: false
        fetchRegistry: false
        service-url:
          defaultZone: http://localhost:8080/eureka
    server:
      port: 9090
    

    5)添加启动参数

    @EnableEurekaClient
    

    6)启动服务

    7)查看注册结果

posted @ 2021-01-18 10:45  Just4life  阅读(139)  评论(0编辑  收藏  举报