【问题标题】:Spring Boot Thymeleaf fragment subdirectory view error with jar带有jar的Spring Boot Thymeleaf片段子目录视图错误
【发布时间】:2014-07-05 12:52:53
【问题描述】:

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

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

文件夹结构

src/main/resources/
---templates/
      ---homepages/
           ---homepage
           ---head

尝试了 Thymeleaf 的显式视图解析器。没有运气。

导致问题的片段。

<head th:include="/homepages/head"></head>

从 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)

使用 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'
}

【问题讨论】:

    标签: jar spring-boot thymeleaf build.gradle spring-java-config


    【解决方案1】:

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

    【讨论】:

    • 成功了,戴夫。谢谢!忽略它,因为在 Spring Boot App 启动和 gradle bootrun 中一切正常。仍然不明白,但会确保坚持正确的语法。
    猜你喜欢
    • 2017-04-14
    • 2021-09-19
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 2017-07-23
    • 2016-02-05
    • 1970-01-01
    相关资源
    最近更新 更多