SpringBoot+Thyemleaf打包jar发到服务器就报错Template might not exist or might not be accessible
SpringBoot+Thyemleaf打包jar发到服务器就报错Template might not exist or might not be accessible
我们这里简单的说明一下报错原因
第一种:Controller层对应的方法返回html路径及名称时,在前面多加了一个/ 。所以,需要将Controller代码中对应return关键字后面第一个"/"去除掉
第二种:检查thymeleaf是否存储在src/main/resources路径下面。如果没有需要在application.yml文件去修改模板的位置;则要求HTML格式必须为严格的html5格式,必须有结束标签,否则会报错
#默认的位置 classpath:/templates
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
第三种:打包配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.relic.RelicApplication</mainClass>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
</build>