/ templates中的Spring-Boot html不会从命令行渲染

时间:2015-02-13 14:07:12

标签: spring-boot

我已经阅读了几个有关此问题的在线帖子,但由于某些原因,这些都没有帮助我解决这个问题。我看了一下春季靴子的例子,我认为我的做法与那些不同。

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

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在大多数情况下配置我的网站。我使用推荐的目录结构: enter image description here

我可以点击索引页面,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"不让我查看网页?

1 个答案:

答案 0 :(得分:2)

事实证明我的REST控制器以“/”开头,因此登录页面变为“// loginPage”并导致问题。我找到了答案here,但我花了一段时间才意识到这是问题所在。希望这个答案可以帮助将来的某个人像熊一样帮助解决问题。