SpringCloud_Eureka

参考文献

快速搭建SpringCloud环境

环境说明

  • Mac
  • Kotlin 1.3.72
  • Gradle 6.4
  • Java 1.8
  • Sping Boot 2.2.0

项目地址

Axin-SpringCloud
如果帮助到了您,动动小手,帮忙给个star。

步骤说明

说明

首先明确兼容的Spring Cloud的版本,可以在这里查询Spring Cloud

这里我贴出来下:
Table 1. Release train Spring Boot compatibility

Release Train Boot Version
Hoxton 2.2.x
Greenwich 2.1.x
Finchley 2.0.x
Edgware 1.5.x
Dalston 1.5.x

因为我的SpingBoot是2.2.0,所以你一会在build.gradle中会看到

springCloudVersion = 'Hoxton.RELEASE'

创建项目

这里快速的过一下,老鸟自己略过。。。

Create_New_Project
Create New Project

Spring_Initiallizr
选择Spring Initiallizr->Project SDK->java 1.8->NEXT

New_Project
Group:输入自己的包名->Artifact:输入自己小写的项目名->Type:Gradle Project ->Language:Kotlin->NEXT

New_Project_2
这里不需要其他依赖->NEXT

New_Project_3

点完成后项目开始构建如下图:

Project_Init

我这里使用的是本地Gradle(建议使用)
叉掉,选择本地Gradle
Select_Gradle

点应用后,更改主项目build.gradle

build.gradle.kts 改为 build.gradle,以下是我已经测试成功的。

group = 'com.axinblog'
version = '0.0.1'

buildscript {

    ext {
        // Required for Kotlin integration
        kotlinVersion = '1.3.72'
        springBootVersion = '2.2.0.RELEASE'
        springCloudVersion = 'Hoxton.RELEASE'
    }

    repositories {
        // 镜像仓库
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'https://maven.aliyun.com/repository/google/' }
        maven { url 'https://maven.aliyun.com/repository/jcenter/' }
        jcenter()
        mavenCentral()
    }

    dependencies {
        // See https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" // Required for Kotlin integration
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion"
        // 让spring-boot支持gradle
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

// 所有的项目配置
allprojects {
    apply plugin: 'java'
    apply plugin: 'idea'
    // Required for Kotlin integration
    apply plugin: 'kotlin'
    // https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support
    apply plugin: "kotlin-spring"
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'

    dependencyManagement {
        // 解决cloud零散jar的版本问题
        imports {
            mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        }
    }

    repositories {
        // 镜像仓库
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'https://maven.aliyun.com/repository/google/' }
        maven { url 'https://maven.aliyun.com/repository/jcenter/' }
        jcenter()
        mavenCentral()
    }

    dependencies {
        implementation('org.springframework.boot:spring-boot-starter-web')
        testCompile('org.springframework.boot:spring-boot-starter-test')

        /**
         * Spring Boot Web应用程序需要3个Kotlin特定的库,并默认配置:
         */
        implementation 'org.jetbrains.kotlin:kotlin-reflect'
        implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
        implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-M1'
    }

    compileKotlin {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }

    compileTestKotlin {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
}

Import_Changes
点Import Changes
等待Gradle构建完成,这里主项目框架就创建完成了