SpringBoot 1024行代码 - Eureka Server

前言

当今的后端服务大多由多个系统构成。有了多个系统就需要有一种通信机制来连通各个系统使之成为一个图。因此RPC这个概念就出现了并且广泛应用在信息技术工业界。国内java语言应用最广泛的RPC框架当属阿里巴巴的开源RPC框架Dubbo。为了支持多系统应用,Spring大家族中产生了一个子工程SpringCloud。SpringCloud本身又由多个独立的功能模块组成。在SpringCloud中有一个RPC调用框架Eureka。本文就来介绍Eureka中的一个子模块Eureka Server的搭建方法。

准备工作

1 安装jdk1.8
2 安装maven
3 具备Spring和SpringMVC的基础知识

具体步骤

1. pom.xml
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <relativePath/>
    </parent>

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
    </dependencies>
2. 创建一个启动类
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
    public static void main(String[] args)
    {
        new SpringApplicationBuilder(EurekaServerApplication.class).web(true).run(args);
    }
}
3. 添加配置application.properties
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:1111/eureka/
spring.application.name=eureka-server
server.port=1111
4. 启动程序并访问http://127.0.0.1:1111/

图片描述

源码

https://github.com/gzllol/spr...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值