Spring-boot-devtools 在Idea中不起作用解決辦法

今天試玩一下Spring-boot,瞬間就愛(ài)上了它,可是發(fā)現(xiàn)并沒(méi)有像傳說(shuō)中的在開(kāi)發(fā)模式下可以不用重啟就看到更新的結(jié)果。經(jīng)過(guò)一番搜索,找到了Spring-boot-devtools,看名字就知道,應(yīng)該是我想要的,趕緊配置。

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

懷著激動(dòng)的心情,run起來(lái),改代碼,刷新頁(yè)面。。。。結(jié)果超出了我的預(yù)期,沒(méi)有任何變化,還是需要重啟服務(wù),甚至只是改html模版也需要重啟。

不死心,繼續(xù)搜索,最終找到了答案,原來(lái)是因?yàn)镮ntellij IEDA和Eclipse不同,Eclipse設(shè)置了自動(dòng)編譯之后,修改類它會(huì)自動(dòng)編譯,而IDEA在非RUN或DEBUG情況下才會(huì)自動(dòng)編譯(前提是你已經(jīng)設(shè)置了Auto-Compile)
設(shè)置其實(shí)很簡(jiǎn)單:

首先,IDEA設(shè)置里面這里必須打勾

image.png

然后 Shift+Ctrl+Alt+/,選擇Registry(Mac 的快捷鍵是:Command+Shift+option+/)

image.png

進(jìn)去之后,找到compiler.automake.allow.when.app.running,打勾

image.png

一切搞定,重啟下項(xiàng)目,然后改動(dòng)代碼后刷新就可以看到結(jié)果了。
另,百度找到的大多數(shù)spring-boot都是用maven構(gòu)建的,我比較喜歡gradle,所以在這貼上build.gradle的代碼以作記錄。

group 'com.cisetech.warm'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.1.4-3'
    ext.spring_boot_version = "1.5.7.RELEASE"

    repositories {
        maven {
            url "http://maven.aliyun.com/nexus/content/groups/public/"
        }
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
    }
}

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'spring-boot'

sourceCompatibility = 1.8

repositories {
    maven {
        url "http://maven.aliyun.com/nexus/content/groups/public/"
    }
    jcenter()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: "$spring_boot_version"
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: "$spring_boot_version"
    compile("org.springframework.boot:spring-boot-devtools:$spring_boot_version")
    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "$spring_boot_version"
}

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

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

bootRun{
    addResources = true
}

最后,在找解決方案的時(shí)候,看到國(guó)外有大神是和Docker一起用,能夠像作Vue項(xiàng)目一樣,改動(dòng)代碼后自動(dòng)瀏覽器上就有變化了,這個(gè)還是沒(méi)懂怎么起效果的,有知道的同學(xué)歡迎mark。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容