eureka与zuul
github地址
build.gradle
buildscript {
ext {
springBootVersion = "2.1.4.RELEASE"
ALIYUN = 'http://maven.aliyun.com/nexus/content/groups/public/'
}
repositories {
maven {
url ALIYUN
}
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
allprojects {
repositories {
maven {
url ALIYUN
}
mavenCentral()
}
}
subprojects {
apply plugin: 'java'
version = '1.0-SNAPSHOT'
group = 'com.huoli'
sourceCompatibility = 1.8
dependencies {
compileOnly 'org.springframework.boot:spring-boot-configuration-processor:2.1.4.RELEASE'
compile 'org.springframework.boot:spring-boot-test-autoconfigure:2.1.4.RELEASE'
compile 'org.projectlombok:lombok:1.18.10'
compile 'org.springframework.boot:spring-boot-starter-test:2.1.4.RELEASE'
}
}
eureka的依赖
dependencies {
compile 'org.springframework.boot:spring-boot-starter-actuator:2.1.4.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web:2.1.4.RELEASE'
compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server:2.1.4.RELEASE'
compile 'com.google.code.gson:gson:2.8.5'
}
eureka yml配置
spring:
application:
name: eureka
server:
port: 1111
eureka:
server:
evictionIntervalTimerInMs: 60000 #清除无效节点的间隔
enableSelfPreservation: true #自我保护
renewalPercentThreshold: 0.85 #触发自我保护的心跳数比例阙值
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:1111/eureka
eureka主类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
zuul的依赖
dependencies {
compile 'org.springframework.cloud:spring-cloud-starter-netflix-zuul:2.1.2.RELEASE'
compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:2.1.2.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-actuator:2.1.4.RELEASE'
compile 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix:2.1.1.RELEASE'
compile 'org.springframework.cloud:spring-cloud-starter-config:2.1.1.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web:2.2.0.RELEASE'
compile 'com.google.code.gson:gson:2.8.5'
}
zuul yml配置
server:
port: 9527
spring:
application:
name: zuul
eureka:
client:
service-url:
defaultZone: http://localhost:1111/eureka
zuul 主类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableZuulProxy
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}