The program works fine in Windows with IDE, but when I release to the jar and run it Ubuntu, it won't render the HTML.
Src:
@Controller
@EnableAutoConfiguration
@RequestMapping("/")
public class JumanController {
@GetMapping("/")
public String index(Model model) {
return "index";
}
...
Main:
@SpringBootApplication
public class App
{
public static void main( String[] args )
{
TomcatURLStreamHandlerFactory.disable();
SpringApplication.run(JumanController.class, args);
}
}
HTML:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
...
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
</dependencies>
</project>
setting:
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/resources/templates/
I tried to change the prefix to classpath:/templates/, still not work.
Warning when server boot:
2018-09-21 10:46:47.154 WARN 4048 --- [ main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
Error when access index:
2018-09-21 10:47:15.253 ERROR 4048 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers
Template dir:
src/main/resources/templates/index.html
Why look for the path src/main/templates/ not src/main/resources/templates/?
I only need a simple Spring boot contains a single static or template page, and could release to a jar. I removed the application.properties want to make everything run as default(AutoConfiguration), But the result is the same.
Any suggestion or hello world demo project will be helpful...