码迷,mamicode.com
首页 > 编程语言 > 详细

快速搭建单机版Spring Cloud EurekaServer

时间:2020-02-28 01:28:32      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:aliyun   https   image   ali   build   snapshot   toc   Delve   url   

原文链接:http://www.yiidian.com/springcloud/build-eureka-single.html

本文介绍搭建单机版的Eureka Server服务

1 创建项目,导入依赖

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.yiidian</groupId>
    <artifactId>eureka-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <relativePath />
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <!-- SpringCloud版本,F系列 -->
        <spring-cloud.version>Finchley.RC1</spring-cloud.version>
    </properties>

    <dependencies>
        <!-- Eureka服务端 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <!-- SpringCloud依赖,一定要放到dependencyManagement中,起到管理版本的作用即可 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

</project>

2 配置Eureka

建立application.yml,内容如下:

server:
  port: 10086 # 端口
  
spring:
  application:
    name: eureka-server # serviceID
    
# 配置Eureka服务
eureka:
  client:
    fetch-registry: false  # 是否拉取Eureka服务器的注册信息,默认true。单机版false,集群版true
    register-with-eureka: false   #  是否向Eureka服务器注册  ,默认true。单机版false,集群版true
    service-url:  # 注册地址
      defaultZone: http://127.0.0.1:${server.port}/eureka

3 编写启动类

package com.yiidian;

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

@EnableEurekaServer  //开启Eurea Server
@SpringBootApplication
public class EurekaServerApplication {
    
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

}

4 运行并访问Eureka Server

运行启动类,浏览器访问: http://localhost:10086,效果如下:
技术图片

技术图片

技术图片

快速搭建单机版Spring Cloud EurekaServer

标签:aliyun   https   image   ali   build   snapshot   toc   Delve   url   

原文地址:https://www.cnblogs.com/yiidian/p/12375278.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!