Spring引导Thymeleaf片段子目录视图错误与jar

use*_*771 5 jar thymeleaf build.gradle spring-boot spring-java-config

我的Spring Boot应用程序在Eclipse中运行良好,在命令行中运行gradle.但是从java -jar启动时无法从子目录加载片段....

使用默认的Spring Boot和Thymeleaf设置和gradle.

文件夹结构

src/main/resources/
---templates/
      ---homepages/
           ---homepage
           ---head
Run Code Online (Sandbox Code Playgroud)

为Thymeleaf尝试了明确的视图解析器.没运气.

片段导致问题.

<head th:include="/homepages/head"></head>
Run Code Online (Sandbox Code Playgroud)

从jar启动时出错

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri May 16 18:54:44 EDT 2014
There was an unexpected error (type=Internal Server Error, status=500).
Error resolving template "/homepages/head", template might not exist or might not be accessible by any of the configured Template Resolvers (homepages/homepage:5)
Run Code Online (Sandbox Code Playgroud)

使用Spring Boot的默认设置.

buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-snapshot" }
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE")
    }
}

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

jar {
    baseName = 'base-app'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-snapshot" }
    maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
}


dependencies {
    compile("org.springframework.boot:spring-boot-starter-web") {
    }
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.thymeleaf:thymeleaf-spring4")
    testCompile("junit:junit")

    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-jdbc")
    compile("org.postgresql:postgresql:9.2-1004-jdbc4")
    compile("org.hibernate:hibernate-validator")
    compile('org.hibernate:hibernate-entitymanager:4.0.1.Final')
    compile("org.springframework:spring-tx")
    compile("org.springframework.boot:spring-boot-starter-actuator")

}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}
Run Code Online (Sandbox Code Playgroud)

Dav*_*yer 2

模板路径通常不以“/”开头。尝试将其从包含路径中删除。