
前回の続き。
コード編集の度にコンパイルが面倒なので、ちょっとわき道にそれて、Spring Loaded を入れて Hot Swap が使えるようにしておく。
UIの調整はブラウザで確認しながら調整するので、都度立ち上げ直しは大変ですしね。
springloaded の設定
build.gradle の buildscript の依存に springloaded を追加する。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE'
classpath 'org.springframework:springloaded:1.2.5.RELEASE'
}
}
IntelliJ IDEA 使っている場合は、以下の設定を入れておく。
idea {
module {
inheritOutputDirs = false
outputDir = file("$buildDir/classes/main/")
}
}
これで自動コンパイルしたファイルの出力先を Gradle のそれに合わせられるので、Spring Loaded で変更が検知できるようになる。
この段階で build.gradle は以下となる。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE'
classpath 'org.springframework:springloaded:1.2.5.RELEASE'
}
}
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
repositories {
jcenter()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.5'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'com.vaadin:vaadin-spring-boot-starter:1.0.0'
compile 'com.h2database:h2:1.4.190'
testCompile 'org.springframework.boot:spring-boot-starter-test'
}
idea {
module {
inheritOutputDirs = false
outputDir = file("$buildDir/classes/main/")
}
}
IntelliJ IDEA の設定
以下の中ほどの「Make project automatically」をチェックして自動コンパイルを有効にしておく。

起動
$ ./gradlew bootRun

IDEでコード変更すると
class VaadinUI extends UI { @Autowired CustomerRepository repo; @Override @CompileStatic protected void init(VaadinRequest request) { VerticalLayout content = new VerticalLayout() content.setMargin(true) setContent(content) // 追加 content.addComponent(new Label("Spring Loaded!")) ・・・ }
追加したラベルが即座に反映されました。
Vaddin デバッグモード
ついでに Vaddin のデバッグコンソール見れるようにしておく。
VaadinServletConfiguration
src/main/groovy/hello/Application.groovy
@SpringUI @Theme("valo") @VaadinServletConfiguration(productionMode = false, ui = VaadinUI.class) class VaadinUI extends UI { ・・・ }
@VaadinServletConfiguration を追加して productionMode を false に設定する。
デバッグコンソールの表示
以下のように?debug を付けてアクセスする。
http://localhost:8080/?debug
デバッグメッセージのログが確認できたり

コンポーネントの階層が確認できたりする。

おしまい。

Spring Boot Cookbook (English Edition)
- 作者:Alex Antonov
- 出版社/メーカー: Packt Publishing
- 発売日: 2015/09/28
- メディア: Kindle版

Vaadin 7 Cookbook (English Edition)
- 作者:Jaroslav Holan,Ondrej Kvasnovsky
- 出版社/メーカー: Packt Publishing
- 発売日: 2013/04/25
- メディア: Kindle版