LoginSignup
4
4

More than 5 years have passed since last update.

Spring Boot + Thymeleafでサンプル作成

Posted at

自分の備忘録として記述。

やったこと

  • Spring BootとThymeleafを使ったサンプル作成(Hello Worldの表示のみ)
  • buildはgradle
  • Thymeleafのtemplatesは任意のディレクトリ(≠ classpath:/resources/)

設定ファイル

build.gradle

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

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

sourceCompatibility = 1.8
version = '1.0'

jar {
    baseName = 'spring-boot-sample'
    version = '1.0.0'
}

repositories {
    mavenCentral()
}

dependencies {
    // for Spring Boot
    compile("org.springframework.boot:spring-boot-starter-web"){
        exclude module: "spring-boot-starter-tomcat"
    }
    compile("org.springframework.boot:spring-boot-starter-jetty")
    compile("org.springframework.boot:spring-boot-starter-actuator")

    // for Thymeleaf
    compile("org.thymeleaf:thymeleaf-spring4:2.1.4.RELEASE")

    // for Coomon Libraries
    compile("org.slf4j:slf4j-api:1.7.10")
    compile("org.slf4j:jcl-over-slf4j:1.7.10")
    compile("ch.qos.logback:logback-classic:1.1.2")
    compile("ch.qos.logback:logback-core:1.1.2")

    testCompile group: 'junit', name: 'junit', version: '4.11'
}

application.properties

spring.thymeleaf.prefix=/WEB-INF/templates/

ハマったこと

spring.thymeleaf.prefixで設定したディレクトリが「/」で終わってなくてもApplicationの起動自体はうまくいくものの

@RequestMapping("/")
public String index()
{
   return "index";
}

で実際にアクセスした際にindexが解決できないというエラーになった。
locationのチェックはするもののprefixはやっぱりprefixなんなんだね。。。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4