Spring Boot 中使用 spring-boot-devtools (使用 Gradle 做爲構建工具)

Spring Boot 中使用 spring-boot-devtools (使用 Gradle 做爲構建工具)

本文使用 Gradle 做爲構建工具,關於 Gradle 構建工具,能夠理解爲是 Maven 的升級版,我我的認爲比 Maven 好的地方是 Gradle 的 Groovy 的語法,比起 Maven 的 xml 語法,看起來要簡潔得多。git

首先,咱們引入阿里巴巴的 Maven 倉庫,加快構建下載的速度

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

引入基本依賴

引入 Spring Boot 最最基礎的依賴:

compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.2.RELEASE'

引入 spring-boot-devtools 的依賴:

compile("org.springframework.boot:spring-boot-devtools")

因此最後看起來是這樣:github

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.2.RELEASE'
    compile("org.springframework.boot:spring-boot-devtools")
}

加入倉庫(很重要,決定了 spring-boot-devtools 可否正確下載)

buildscript {
    ext {
        springBootVersion = '1.5.2.RELEASE'
    }
    repositories {
        // NOTE: You should declare only repositories that you need here
        mavenLocal()
        mavenCentral()
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        maven { url "http://repo.spring.io/release" }
        maven { url "http://repo.spring.io/milestone" }
        maven { url "http://repo.spring.io/snapshot" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

加入插件(很重要,決定了 spring-boot-devtools 可否正確下載)

這裏就一句話,這句話,我測試了好久才發現這句話必須加上去。web

apply plugin: 'spring-boot'

這時,咱們就能夠刷新 Gradle,看到全部的依賴都正常下載。spring

到這裏配置文件的配置就告一段落了,下面咱們還要配置 IntelliJ IDEA。intellij-idea

配置 IntelliJ IDEA

勾選 Build project automatically 選項前的單選按鈕。

接下來的設置

一、mac 電腦按下 command + alt + shift + / 出現:
app

二、找到 「compiler.automake.allow.when.app.running」 這個選項,而且勾選:
maven

此致,就大功告成了。ide

示例項目 GitHub 所在地址:https://github.com/weimingge14/SpringBootDevToolspring-boot

參考資料:
一、Intellij IDEA 使用Spring-boot-devTools無效解決辦法工具

相關文章
相關標籤/搜索