I have the following controller:
@Controller
public class ConfigController {
@GetMapping("/")
public String index() {
return "config";
}
}
However I receive the following error when going to the route /
:
There was an unexpected error (type=Internal Server Error, status=500).
Error resolving template [config], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [config], template might not exist or might not be accessible by any of the configured Template Resolvers
I have a config.html
file inside of resources/templates
:
My pom.xml file: https://pastebin.com/yqYYuXWh
What am I doing wrong?
I have already tried adding a .html
to the return of the controller function, but it still doesn't work.
After removing the spring-web dependency (I already had spring-boot-starter-web
) I now get the following error when starting spring:
Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
CodePudding user response:
The issue is in your pom.xml file.
By adding this block to your build
;
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.properties</include>
</includes>
</resource>
</resources>
You have overriden spring-boot-starter-parent
's own resources
block and caused it to include application.properties
and nothing else. Remove it from your pom.xml and delete your target directory.
CodePudding user response:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.20</version>
</dependency>
The second dependency is not required.
<build>
<!--not required. Spring boot scans /resources directory by default
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.properties</include>
</includes>
</resource>
</resources>
-->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Please rebuild and restart the app again.