热门标签 | HotTags
当前位置:  开发笔记 > 运维 > 正文

spring-cloud入门之eureka-server(服务发现)

前言 Eureka是一个服务发现和注册框架,细的来说,我们可以分为eureka-server(服务发现)和eureka-client(服务

前言

Eureka是一个服务发现和注册框架,细的来说,我们可以分为eureka-server(服务发现)和eureka-client(服务注册)两个,本次我们对eureka-server(服务发现)做一个项目搭建,作为spring-cloud的开篇。

开源地址:https://github.com/bigbeef

项目结构

maven结构大家应该都清楚(不清楚的需要补一补,百度关于maven的文章不计其数),下面我们来看一看这些关键文件的配置

代码编写

cppba-spring-cloud > pom.xml


  4.0.0
  com.cppba
  cppba-spring-cloud
  1.0.0
  pom
  ${project.artifactId}

  
    org.springframework.boot
    spring-boot-starter-parent
    1.5.5.RELEASE
  

  
    UTF-8
    1.8
    Dalston.SR2
  

  
    
      
        org.springframework.cloud
        spring-cloud-dependencies
        ${spring-cloud.version}
        pom
        import
      
    
  

  
    cppba-spring-cloud-eureka-server
  

cppba-spring-cloud-eureka-server > pom.xml

<&#63;xml version="1.0" encoding="UTF-8"&#63;>

  4.0.0
  cppba-spring-cloud-eureka-server
  jar
  ${project.artifactId}

  
    com.cppba
    cppba-spring-cloud
    1.0.0
  

  
    
      org.springframework.cloud
      spring-cloud-starter-eureka-server
    
  

    
    ${project.name}
    
      
      
        org.springframework.boot
        spring-boot-maven-plugin
      
    
   

SpringCloudEurekaServerApplication.java

package com.cppba;

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

@EnableEurekaServer
@SpringBootApplication
public class SpringCloudEurekaServerApplication {

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

application.properties

server.port=8761

eureka.instance.hostname=eureka-server
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZOne=http://${eureka.instance.hostname}:${server.port}/eureka/

到此项目搭建完成

启动项目

我们启动SpringCloudEurekaServerApplication中的main方法,访问http://127.0.0.1:8761

到此,eureka-server(服务发现)项目搭建成功

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


推荐阅读
author-avatar
mobiledu2502905727
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有