Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Thymeleaf fragment subdirectory view error with jar

My Spring Boot app works fine in Eclipse and from gradle run in command line. However fails to load fragment from a sub directory when launched from java -jar....

Using default Spring Boot and Thymeleaf settings and gradle.

Folder structure

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

Tried explicit view resolver for Thymeleaf. No luck.

fragment causing problem.

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

error when launched from 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)

Using default setting for 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'
}
like image 996
user2880771 Avatar asked Oct 31 '22 23:10

user2880771


1 Answers

Template paths normally do not start with "/". Try removing that from your include path.

like image 200
Dave Syer Avatar answered Nov 09 '22 17:11

Dave Syer