Reputation: 59
I'm having an issue getting my spring boot application to load up my simple webpage. I have copied the examples that were provided here and implemented them in the templates directory I keep getting this error
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers
Here is a look at the file directory
This is everything that's in the controller class
package com.example.cloud_computing_project;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HomeController {
@GetMapping("/")
private String OpenMainPage() {
return "index";
}
}
Here is what the build.gradle looks like
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
ext {
set('springCloudVersion', "Hoxton.RC2")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
//implementation 'org.springframework.cloud:spring-cloud-starter-aws-messaging'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
I have looked around and as far as I can tell, the files are right, the location of the files are right, and the getmapping pointing to the location is right. Only thing I can see being wrong is that I might be missing a dependancy in my build.gradle
Any help would be GREATLY appreciated thank you.
Upvotes: 1
Views: 2722
Reputation: 59
I started to get curious if anything else wasn't working. So I included "server.port=8081" in the application.properties file. This did not take when I ran it. With this in mind, and that the output is stating it can't find the templates folder under classpath:/ I started to wonder if somehow the defaults were being overwritten by something.
I did not alter any configurations at all. The only thing I did was configure the build.gradle to import dependencies and that was it.
I found a forum that suggested to run it with the gradle.Tasks.Application.bootRun
This did fix the issues I was having. It was now finding the templates folder and loading my index.html file. It also was using the application.properties file. However, since this wasn't being built and ran by IntelliJ it wasn't color-coding the output.
According to this issue the suggested fix was to re-import the project.
I had already pushed my project to a git repository and the .gitignore doesn't push any of the files that could cause this issue. So I deleted my entire working directory and then cloned the pushed repository.
IT WORKED! Everything is working fine now. application.properties is working and my HTML files are being loaded successfully under /src/main/resources/templates
Also thanks to @MohamedSanaulla for his suggestion on layout dialect dependency. I was having trouble with that too until I added the implementation in gradle.
Upvotes: 0
Reputation: 6252
In Spring Boot Thymeleaf Starter 2.0 onwards you need to explicitly include ultraq thymeleaf layout dialect dependency. In Maven it would be:
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
Upvotes: 1