Spring Bootのデプロイ

Spring Bootのデプロイ

build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE'
+       classpath 'org.springframework:springloaded:1.2.1.RELEASE'
    }
}

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

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-web'
}

jar.baseName = 'spring-boot-sample'

buildscriptの依存関係にorg.springframework:springloaded:1.2.1.RELEASEを追加します。その後、通常どおりgradle bootRunを実行するとデプロイが有効になります。

Thymeleafを使用する場合

テンプレートエンジンにThymeleafを使用する場合は、キャッシュを無効にします。

application.properties

spring.thymeleaf.cache=false

Thymeleaf以外のテンプレートエンジンを使用する場合は、このページを参照してください。

IntelliJ IDEAを使用する場合

build.gradleに次の内容を追加します。

build.gradle

apply plugin: 'idea'

idea {
    module {
        inheritOutputDirs = false
        outputDir = file("$buildDir/classes/main/")
    }
}

デフォルトでは、IntelliJのコンパイル結果の出力先がGradleと異なるため、ファイル監視が正しく動作しません。上記のように関連設定を変更します。

参考: 80. Hot swapping