idea上gradle與springcloud的簡單搭建(二)


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);
    }
}

build.gradle講解地址
eureka與zuul地址
生產與消費地址


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM