前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring Cloud(1)——服务注册中心

Spring Cloud(1)——服务注册中心

作者头像
会跳舞的机器人
发布2018-09-21 16:15:54
5910
发布2018-09-21 16:15:54
举报

一、简介

Eureka是一个云端服务发现,一个基于 REST 的服务,用于定位服务,以实现云端中间层服务发现和故障转移。用它我们可以实现服务注册与发现功能

二、项目实例

1、创建Maven工程microservice-eureka-server,并在pom.xml中加入以下依赖包

代码语言:javascript
复制
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-eureka-server</artifactId>
    </dependency>
  </dependencies>

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

2、创建应用启动类EurekaServerApplication.java

代码语言:javascript
复制
package com.baibei.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

/**
 * @author: 会跳舞的机器人
 * @email:2268549298@qq.com
 * @date: 17/2/15 下午5:39
 * @description:启动主类
 */
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

}

使用@EnableEurekaServer注解开启服务注册功能

3、配置application.yml

在resource目录下创建application.yml文件,内容如下:

代码语言:javascript
复制
spring:
  application:
    name: microservice-eureka-server
server:
  port: 8761
eureka:
  instance:
    hostname: eureka-server
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://eureka-server:8761/eureka/
4、启动运行

运行EurekaServerApplication的main方法,启动成功后,访问:http://localhost:8761/

Paste_Image.png
Paste_Image.png

从图中我们可以看出,还没有任何服务注册至注册中心。

附项目目录截图:

Paste_Image.png
Paste_Image.png
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-11-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、简介
  • 二、项目实例
  • 1、创建Maven工程microservice-eureka-server,并在pom.xml中加入以下依赖包
  • 2、创建应用启动类EurekaServerApplication.java
  • 3、配置application.yml
    • 4、启动运行
    相关产品与服务
    微服务引擎 TSE
    微服务引擎(Tencent Cloud Service Engine)提供开箱即用的云上全场景微服务解决方案。支持开源增强的云原生注册配置中心(Zookeeper、Nacos 和 Apollo),北极星网格(腾讯自研并开源的 PolarisMesh)、云原生 API 网关(Kong)以及微服务应用托管的弹性微服务平台。微服务引擎完全兼容开源版本的使用方式,在功能、可用性和可运维性等多个方面进行增强。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档