Spring-在 /templates 中启动 html 不从命令行呈现

Spring-Boot html in /templates don't render from command line

我已经阅读了几篇关于这个问题的在线帖子,但出于某种原因,其中 none 帮助我解决了这个问题。我查看了 spring-boot 示例,我认为我所做的与那些没有太大不同。

我正在使用 Spring-boot 1.2.1,Thymeleaf,嵌入式 tomcat 在 IntelliJ 中没有问题。但是,当我执行 "gradle clean build" 时,将 jar 文件和 application.properties 文件移动到部署目录。然后我开始执行命令:

java -jar edm-0.1.0.jar

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/loginPage", template might not exist or might not be accessible by any of the configured Template Resolvers
    at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245)

我让 spring-boot 大部分配置我的网站。我正在使用推荐的目录结构:

我可以访问索引页,而且 REST 调用似乎工作正常。

根据反馈更新: 我不知道这是否是一个损坏的 jar 问题,但是当我提取它时,结构和文件看起来是正确的。我可以从项目结构的顶部 运行 "gradle bootRun" 就好了。但是如果我部署 jar 文件并 运行 它,我会得到一个错误:

Task 'bootRun' not found in root project 'edm'

这是我的 build.gradle 文件,以防其中出现问题:

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'maven'

idea {
    project {
        //if you want to set specific jdk and language level
        jdkName = '1.8'
        languageLevel = '1.8'
    }
}

jacoco {
    toolVersion = "0.7.0.201403182114"
}

project.ext {
    springBootVersion = '1.2.1.RELEASE'
}

configurations {
    querydslapt
}

buildscript {
    repositories {
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
        maven { url "http://repo.spring.io/libs-milestone" }
        maven { url "http://repo.spring.io/libs-snapshot" }
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
    }
}

jar {
    baseName = 'edm'
    version = '0.1.0'
}

dependencies {
    querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier:   'apt-one-jar', transitive: false

    compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
    compile("org.springframework.security:spring-security-web:4.0.0.M1")
    compile("org.springframework.security:spring-security-config:4.0.0.M1")
    compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.1.RELEASE')

    compile('com.android.tools.build:gradle:1.0.1')

    compile("org.hibernate:hibernate-core:4.3.4.Final")
    compile("org.hibernate:hibernate-entitymanager:4.3.4.Final")
    compile("org.hibernate:hibernate-validator")

    compile("org.apache.velocity:velocity:1.7")
    compile('javax.mail:mail:1.4.1')
    compile("org.springframework:spring-context-support")
    compile("com.h2database:h2:1.3.172")
    compile("joda-time:joda-time:2.3")
    compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.5.0")
    compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")
    compile('org.codehaus.groovy:groovy-all:2.2.1')
    compile('org.jadira.usertype:usertype.jodatime:2.0.1')

    compile("postgresql:postgresql:9.1-901.jdbc4")

    testCompile('org.spockframework:spock-core:1.0-groovy-2.0-SNAPSHOT') {
        exclude group: 'org.codehaus.groovy', module: 'groovy-all'
    }

    testCompile('org.spockframework:spock-spring:1.0-groovy-2.0-SNAPSHOT') {
        exclude group: 'org.spockframework', module: 'spock-core'
        exclude group: 'org.spockframework', module: 'spring-beans'
        exclude group: 'org.spockframework', module: 'spring-test'
        exclude group: 'org.codehaus.groovy', module: 'groovy-all'
    }
    testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
    testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
    testCompile("junit:junit")


    // for the anontation processor
    querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
// for compiling
    compile("com.mysema.querydsl:querydsl-jpa:3.3.3")
    compile("com.mysema.querydsl:querydsl-apt:3.3.3")
}

task wrapper(type: Wrapper) {
        gradleVersion = '2.0'
}
project.configurations {
    providedRuntime
    }

project.bootRepackage {
    enabled = true
    }

我还尝试在我的 application.properties 文件中添加一些 thymeleaf 配置(即使我没有明确使用 Thymeleaf):

liquibase.changeLog=classpath:/db/changelog/db.changelog-master.xml
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.check-template-location=true

所以我想我的问题是,为什么 运行 宁 "java -jar" 不让我查看网页?

事实证明,我的 REST 控制器以“/”开头,因此登录页面变成了“//loginPage”,这就是导致问题的原因。我找到了答案 here,但我花了一段时间才意识到这就是问题所在。希望这个答案能帮助将来的人,因为它很容易弄清楚。