之前使用dubbo搭建了一个系统,不过搭的不是很好,最近开始学Spring Cloud微服务,我感觉Spring Cloud要比dubbo要好用多了,以前在搭dubbo的时候还没有写博客的习惯,很多东西都没有去总结久而久之就忘记了,所以这次学习Spring Cloud我会把自己学习的整个过程都记录下来,既能给自己增加记忆,方便查看,还能和大家分享。
好了,废话不多说,开始Spring Cloud的学习,希望和大家共同进步。
准备环境
- JDK 1.8
- IDEA 社区版
- spring boot 2.0.3
- maven 3.2.2
创建服务注册中心
使用IDEA快速创建一个Spring Boot工程,添加Eureka Server组件。【IDEA 社区版 创建spring cloud项目】
Eureka Server依赖
我选择spring boot的版本是2.0.3,spring cloud的版本是Finchley.SR3,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.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>clarezhou.example</groupId>
<artifactId>eureka-server-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>eureka-server-test</name>
<description>Eureka Server</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR3</spring-cloud.version>
</properties>
<dependencies>
<!-- Eureka Server依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<op