spring-cloud

Spring Cloud 学习笔记

Spring Cloud学习项目

Gradle初始化项目

1
$ mkdir spring-cloud-learning

gradle初始化项目

1
$ cd spring-cloud-learning && gradle init

修改spring-cloud-learning目录下的build.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
}

allprojects {
group = "org.azaleaframework"
version '0.0.1-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'idea'
}

subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
mavenCentral()
}

dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Greenwich.RELEASE'
}
}
}

eureka服务注册中心

在spring-cloud-learning目录下创建eureka-server子模块

1
$ mkdir -p eureka-server/src/{main,test}/{java,resources}

在spring-cloud-learning目录下的settings.gradle中引入eureka-server子模块

1
include 'eureka-server'

在eureka-server添加build.gradle配置文件

1
touch eureka-server/build.gradle

修改eureka-server目录下的build.gradle配置文件

1
2
3
4
5
6
archivesBaseName = 'eureka-server'

dependencies {
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

eureka服务提供者

在spring-cloud-learning目录下创建eureka-service-provider子模块

1
$ mkdir -p eureka-service-provider/src/{main,test}/{java,resources}

在spring-cloud-learning目录下的settings.gradle中引入eureka-service-provider子模块

1
include 'eureka-service-provider'

在eureka-service-provider添加build.gradle配置文件

1
touch eureka-service-provider/build.gradle

修改eureka-service-provider目录下的build.gradle配置文件

1
2
3
4
5
6
7
archivesBaseName = "eureka-service-provider"

dependencies {
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

eureka服务消费者

在spring-cloud-learning目录下创建eureka-service-consumer子模块

1
$ mkdir -p eureka-service-consumer/src/{main,test}/{java,resources}

在spring-cloud-learning目录下的settings.gradle中引入eureka-service-consumer子模块

1
include 'eureka-service-consumer'

在eureka-service-consumer添加build.gradle配置文件

1
touch eureka-service-consumer/build.gradle

修改eureka-service-consumer目录下的build.gradle配置文件

1
2
3
4
5
6
7
archivesBaseName = "eureka-service-consumer"

dependencies {
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

Config 配置文件

在spring-cloud-learning目录下创建config-repo子模块

1
$ mkdir config-repo

Config服务端

在spring-cloud-learning目录下创建config-server子模块

1
$ mkdir -p config-server/src/{main,test}/{java,resources}

在spring-cloud-learning目录下的settings.gradle中引入config-server子模块

1
include 'config-server'

在econfig-server添加build.gradle配置文件

1
touch config-server/build.gradle

修改config-server目录下的build.gradle配置文件

1
2
3
4
5
6
7
archivesBaseName = 'config-server'

dependencies {
compile('org.springframework.cloud:spring-cloud-config-server')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}