最近一段时间重新学习一边SpringCloud,这里简单记录一下。

我用的是IntelliJ IDEA开发工具, SpringBoot的版本是2.1.3.RELEASE。

1. 构建Maven项目

整个的SpringCloud的项目是在Maven项目中的,这个Maven只做容纳其他项目使用, 比如后面Fegin/Config/Zipkin等项目。

用IntelliJ IDEA工具, File->Project->spring Initializr, 然后点击next, 填写Group和Artifact等信息.

比如我填写的GroupId是com.xum, ArtifactId是demo, 然后next, 在这里我们什么也不选择,再次点击next,

最后选择存放位置,然后Finshed.

把生成pom.xml改成如下(因为这个只是做存放项目使用, 还要把这个src文件也删除了)

<?xml version="1.0" encoding="UTF-8"?>
<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.xum</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version> </project>

2. 构建Eureka-Server项目

在我们生成的Demo项目上右键点击New->Module->spring Initializr, 然后next, 填写Group和Artifact等信息,

这里Artifact填写eurekaserver, 再次next, 如下图,

选择Web下的web和Cloud Discovery下的Eureka Server.

最后在Module Name中填写eureka-server.

生成的pom.xml文件如下

<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xum</groupId>
<artifactId>eureka-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-server</name>
<description>Demo project for Spring Boot</description> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<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> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> <repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories> </project>

然后在src->main->resources下新建application.yml文件,把其他的都删除, 内容如下

server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

最后在EurekaServerApplication 上面添加@EnableEurekaServer这个注解

package com.xum.eurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication { public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
} }

通过Run DashBoard运行eureka-server

运行成功以后,用浏览器打开http://localhost:8761, 显示如下,说明eureka-server搭建成功.

下一节将如何构建eureka-client.

SpringCloud的学习记录(1)的更多相关文章

  1. SPRINGCLOUD 开发学习记录

    一个简单的微服务系统:服务注册和发现,服务消费,负载均衡,断路器,智能路由,配置管理 服务注册中心: eureka是一个高可用组件,没有后端缓存,每一个实例注册后向注册中心发送心跳,默认情况下,eru ...

  2. SpringCloud的学习记录(8)

    这一章节讲zipkin-server. 在我们生成的Demo项目上右键点击New->Module->spring Initializr, 然后next, 填写Group和Artifact等 ...

  3. SpringCloud的学习记录(7)

    这一章节讲zuul的使用. 在我们生成的Demo项目上右键点击New->Module->spring Initializr, 然后next, 填写Group和Artifact等信息, 这里 ...

  4. SpringCloud的学习记录(6)

    这一章节讲fegin的使用. 在我们生成的Demo项目上右键点击New->Module->spring Initializr, 然后next, 填写Group和Artifact等信息, 这 ...

  5. SpringCloud的学习记录(5)

    这一章节讲如何使用ribbon和hystrix. 在我们生成的Demo项目上右键点击New->Module->spring Initializr, 然后next, 填写Group和Arti ...

  6. SpringCloud的学习记录(3)

    这一章节讲搭建config-server的项目. 在我们生成的Demo项目上右键点击New->Module->spring Initializr, 然后next, 填写Group和Arti ...

  7. SpringCloud的学习记录(2)

    这一章节主要讲如何搭建eureka-client项目. 在我们生成的Demo项目上右键点击New->Module->spring Initializr, 然后next, 填写Group和A ...

  8. SpringCloud的学习记录(4)

    本篇基于上一篇写的, 在git上更改配置后, eureka-client如何更新. 我们只需要在配置文件中配置 spring-cloud-starter-bus-amqp; 这就是说我们需要装rabb ...

  9. SpringCloud基础教程学习记录

    这个学习记录是学习自翟永超前辈的SpringCloud的基础教程. 自己写这个教程的目的主要是在于,想要更凝练总结一些其中的一些实用点,顺便做个汇总,这样自己在复习查看的时候更加方便,也能顺着自己的思 ...

随机推荐

  1. uwsgi01---uwsgi文件

    1. 安装 pip install uwsgi //测试uWSGI是否安装成功 在终端中输入以下命令查看uwsgi的版本:uwsgi --version 2.简单运行 运行uwsgi:uwsgi -- ...

  2. Visible Ops

    Link:http://www.wikisummaries.org/Visible_Ops Contents [hide]  1 What is ITIL? 2 Introduction 3 Phas ...

  3. 根据map中某一字段排序

    以上是从小到大的排序...要注意.! 需要jdk8...

  4. js 的 一些操作。。。

    // 对错误图片进行处理 $("img").error(function() { $(this).attr("src", "http://127.0. ...

  5. 找出区间[A, B]内所有数字的奇数字位出现次数为偶数,偶数字位出现次数为计数的数的个数。(数位DP)

    题目:找出区间[A, B]内所有数字的奇数字位出现次数为偶数,偶数字位出现次数为计数的数的个数. 分析:这道题的状态同样不好取,因为要求每一个奇数的个数都要为偶数,每一个偶数的位数都要为奇数,又因为只 ...

  6. Ubuntu 安装 phpredis扩展

    官网 https://github.com/phpredis/phpredis 下载->然后解压->上传服务器 /etc/phpredis 进行 cd /etc/phpredisphpiz ...

  7. vue 之 nextTick 与$nextTick

    VUE中Vue.nextTick()和this.$nextTick()怎么使用? 官方文档是这样解释的: 在下次 DOM 更新循环结束之后执行延迟回调.在修改数据之后立即使用这个方法,获取更新后的 D ...

  8. 跨域的问题(jsonp和cors)

    由于浏览器的同源策略,用户想要跨域访问浏览器就会报错,那么就涉及到解决跨域的问题.最近我接触到的解决方法是两个,jsonp和cors. jsonp(json with padding)我们虽然不能直接 ...

  9. C# 连接 Exchange 发送邮件

    C#连接Exchange 发送邮件代码如下 /// <summary> /// exchange群发邮件 /// </summary> /// <param name=& ...

  10. Win7 IIS 局域网中无法访问网页

    安装好iis后,在局域网中无法浏览网页一,关闭防火墙即可 或者建立入站规则 打开控制面板——window防火墙——高级设置 在入站规则上右键新建入站规则,选择端口然后下一步 选择tcp和特定端口在端口 ...