• 说明

    • SpringBoot版本 2.1.7.RELEASE
    • SpringCloud版本 Greenwich.SR2
  1. 创建eureka server工程

    1. 加入pom依赖

      <dependencies>
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
      </dependency>
      </dependencies> <dependencyManagement>
      <dependencies>
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>Greenwich.SR2</version>
      <type>pom</type>
      <scope>import</scope>
      </dependency>
      </dependencies>
      </dependencyManagement>  
    2. 启动类添加@EnableEurekaServer注解
      @EnableEurekaServer
      @SpringBootApplication
      public class EurekaApplication { public static void main(String[] args) {
      SpringApplication.run(EurekaApplication.class, args);
      } }
    3. application.yml文件中添加配置
      server:
      port: 8761 spring:
      application:
      name: servers-register eureka:
      instance:
      hostname: localhost
      client:
      register-with-eureka: false
      fetch-registry: false
      service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      server:
      wait-time-in-ms-when-sync-empty: 0
      enable-self-preservation: false

      注意:这里是单机版配置

  2. 创建eureka client工程

    1. 加入pom依赖

      <dependencies>
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
      </dependency>
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      </dependency>
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      </dependencies> <dependencyManagement>
      <dependencies>
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>Greenwich.SR2</version>
      <type>pom</type>
      <scope>import</scope>
      </dependency>
      </dependencies>
      </dependencyManagement>
    2. 启动类添加@EnableDiscoveryClient注解
      @EnableDiscoveryClient
      @SpringBootApplication
      public class UserServerApplication { public static void main(String[] args) {
      SpringApplication.run(UserServerApplication.class, args);
      } }
    3. application.yml添加配置
      server:
      port: 8081

      eureka:
      client:
      service-url:
      defaultZone: 'http://localhost:8761/eureka/'

      spring:
      application:
      name: user-server

      注意:这里的spring.application.name服务自定义名称,如果不定义的话,在eureka server的界面中展示的是UNKNOWN

  3. 启动server和client项目,访问localhost:8761

    提示:这里的USER-SERVER名称就是user-client工程配置文件中的 spring.application.name

SpringCloudEureka入门的更多相关文章

  1. SpringCloud入门1-服务注册与发现(Eureka)

    前言 Oracle转让Java,各种动态语言的曝光率上升,Java工程师的未来在哪里?我觉得Spring Cloud让未来有无限可能.拖了半年之久的Spring Cloud学习就从今天开始了.中文教材 ...

  2. springcloud入门系列

    关于springcloud 1.写在前面 写着写这,不知不觉springcloud写了7,8篇了,今天把文章分下类,写下感受及后面的计划吧. (1)springcloud中最最重要的是eureka注册 ...

  3. 优质分享 | Spring Boot 入门到放弃!!!

    持续原创输出,点击上方蓝字关注我 目录 前言 视频目录 如何获取? 总结 前言 最近不知不觉写Spring Boot专栏已经写了九篇文章了,从最底层的项目搭建到源码解析以及高级整合的部分,作者一直在精 ...

  4. Angular2入门系列教程7-HTTP(一)-使用Angular2自带的http进行网络请求

    上一篇:Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数 感觉这篇不是很好写,因为涉及到网络请求,如果采用真实的网络请求,这个例子大家拿到手估计还要自己写一个web ...

  5. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  6. Oracle分析函数入门

    一.Oracle分析函数入门 分析函数是什么?分析函数是Oracle专门用于解决复杂报表统计需求的功能强大的函数,它可以在数据中进行分组然后计算基于组的某种统计值,并且每一组的每一行都可以返回一个统计 ...

  7. Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数

    上一篇:Angular2入门系列教程5-路由(一)-使用简单的路由并在在路由中传递参数 之前介绍了简单的路由以及传参,这篇文章我们将要学习复杂一些的路由以及传递其他附加参数.一个好的路由系统可以使我们 ...

  8. Angular2入门系列教程5-路由(一)-使用简单的路由并在在路由中传递参数

    上一篇:Angular2入门系列教程-服务 上一篇文章我们将Angular2的数据服务分离出来,学习了Angular2的依赖注入,这篇文章我们将要学习Angualr2的路由 为了编写样式方便,我们这篇 ...

  9. Angular2入门系列教程4-服务

    上一篇文章 Angular2入门系列教程-多个组件,主从关系 在编程中,我们通常会将数据提供单独分离出来,以免在编写程序的过程中反复复制粘贴数据请求的代码 Angular2中提供了依赖注入的概念,使得 ...

随机推荐

  1. vue实现手机号码的校验(防抖函数的应用场景)

    上一篇博文我们讲到了节流函数的应用场景,我们知道了节流函数可以用在模糊查询.scroller.onresize等场景:今天这篇我们来讲防抖函数的应用场景:: 通过上一篇博文的学习,我们知道了防抖函数的 ...

  2. springboot事务中的一些坑

    springboot开启声明式事务方式 在Application启动类中加入注解@EnableTransactionManagement(mode = AdviceMode.PROXY) 在需要加入事 ...

  3. C++string,char* 字符数组,int类型之间的转换

    string.int 常见类型之间相互转换 int & string 之间的转换 C++中更多的是使用流对象来实现类型转换 针对流对象 sstream实现 int,float 类型都可以实现 ...

  4. POJ 1002 487-3279 map

    487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 287874   Accepted: 51669 Descr ...

  5. 洛谷 P4206 [NOI2005]聪聪与可可 题解

    题面 输入 数据的第1行为两个整数N和E,以空格分隔,分别表示森林中的景点数和连接相邻景点的路的条数. 第2行包含两个整数C和M,以空格分隔,分别表示初始时聪聪和可可所在的景点的编号. 接下来E行,每 ...

  6. git连接远程分支

    今天在再用git连接到远程的dev分支的时候出现了下面的情况 $ git checkout -b dev origin/dev fatal: 'origin/dev' is not a commit ...

  7. Git暂存本地代码,强制获取远程最新代码

    一:git stash  // 把本地修改的代码压到git栈中去 二:git pull  // 本地代码压栈之后,pull远程代码会完全覆盖本地代码 三:git stash list  // 可以查看 ...

  8. iOS组件化实践

    参考资料: http://wereadteam.github.io/2016/03/19/iOS-Component/#more https://casatwy.com/iOS-Modulizatio ...

  9. tomcat日志信息查看

    不要老只看 start in xxx ms 后的信息,有时在部署项目时可能就出错了呢? 按照下面这样子做,会使用tomcat输出的错误信息更为详细 在WEB-INF/classes目录下新建一个名为 ...

  10. OPC-System.Runtime.InteropServices.COMException:“Error HRESULT E_FAIL has been returned from a call to a COM component.”

    Error HRESULT E_FAIL has been returned from a call to a COM component的错误提示,还是因为OPC配置,这次是红框中标签定义错误,应该 ...