Spirng Cloud可以很容易的实现注册中心,进行服务的注册,进行服务的消费
本例子是采用gradle来实现的
首先项目结构图:
根目录gradle配置
settings.gradle
rootProject.name = 'springCloud'
include ':eureka'
include ':provider'
include ':test'
build.gradle
group 'com.zoo'
version '1.0-SNAPSHOT'
subprojects {
group 'com.zoo'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "Greenwich.SR1")
set('javaVersion', "1.8")
}
}
eureka注册中心
build.gradle
plugins {
id 'org.springframework.boot' version '2.1.5.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = javaVersion
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
application.yml
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
spring:
appli