IntellijでSpring Boot を tomcatで

IDEIntellij

フレームワーク:Spring Boot 

APサーバ:tomcat

 

上記でいろいろと挑戦してみる。

 

new → projectでGradleのプロジェクトを作成。

プロジェクト名・グループ名を適当に決め「build.gradle」に下記を貼り付け。

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.9.RELEASE")
        classpath("org.springframework:springloaded:1.2.1.RELEASE")
    }
}

apply plugin: 'idea'
apply plugin: 'spring-boot'

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

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.1.9.RELEASE")

}

 

javaクラス・controllerクラスを作成しbuild。

bootrunで実行すると早速山ほどエラーが。

【エラー内容】

Process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' finished with non-zero exit value 1

 謎。

よくよくエラー内容を見てみると、

IllegalStateException: Cannot find template location: class path resource [templates/]

と書いてある。 

 どうやら、main/resources/templatesディレクトリが存在しない場合に起きるエラーらしい。

ディレクトリを作成して再度bootrun実行。

2016-06-01 08:26:13.465  INFO 8596 --- [           main] sample_one.sample.Application            : Started Application in 23.845 seconds (JVM running for 25.93)

tomcatの起動OK

 

http://localhost:8080/test

 

を開いてみると無事開けている。

 

しかし、java.lang.reflect.InvocationTargetException: nullのエラーが出ているのは事実。

もう少し調べてみる。