Java 在eclipse中可以很好地工作,但是;Can';“找不到模板”;如果作为jar运行

Java 在eclipse中可以很好地工作,但是;Can';“找不到模板”;如果作为jar运行,java,maven,spring-boot,thymeleaf,Java,Maven,Spring Boot,Thymeleaf,该程序在带有IDE的Windows中运行良好,但当我释放到jar并运行Ubuntu时,它不会呈现HTML Src: 主要内容: HTML: 我试图将前缀更改为类路径:/templates/,但仍然不起作用 服务器启动时发出警告: 2018-09-21 10:46:47.154警告4048---[main] ion$DefaultTemplateResolverConfiguration:找不到模板 位置:classpath:/templates/(请添加一些模板或检查 您的手机配置) 访问索引时

该程序在带有IDE的Windows中运行良好,但当我释放到jar并运行Ubuntu时,它不会呈现HTML

Src:

主要内容:

HTML:

我试图将
前缀
更改为
类路径:/templates/
,但仍然不起作用

服务器启动时发出警告:

2018-09-21 10:46:47.154警告4048---[main] ion$DefaultTemplateResolverConfiguration:找不到模板 位置:classpath:/templates/(请添加一些模板或检查 您的手机配置)

访问索引时出错:

2018-09-21 10:47:15.253错误4048---[nio-8080-exec-1] org.thymeleaf.TemplateEngine: [ThymileAF][http-nio-8080-exec-1]异常处理模板 “索引”:解析模板“索引”时出错,模板可能不存在或 任何已配置的模板解析程序都可能无法访问

org.thymeleaf.exceptions.TemplateInputException:错误解析 模板“索引”,模板可能不存在或不可访问 由任何已配置的模板解析程序执行

模板目录:

src/main/resources/templates/index.html
为什么要查找路径
src/main/templates/
而不是
src/main/resources/templates/

我只需要一个简单的
springboot
包含一个
static
template
页面,并且可以释放到一个jar中。我删除了application.properties,我想让一切都默认运行(自动配置),但结果是一样的

任何建议或hello world演示项目都会很有帮助…

已解决:

  • 将模板目录从
    src/main/resources/templates/
    更改为
    /resources/templates/
    。(与
    src
    相同级别)

  • 将spring.thymeleaf.prefix设置为
    classpath:/templates/


  • 源代码:

    确保application.properties文件包含以下条目- spring.thymeleaf.prefix=类路径:/templates/

    @SpringBootApplication
    public class App 
    {
        public static void main( String[] args )
        {
            TomcatURLStreamHandlerFactory.disable();
            SpringApplication.run(JumanController.class, args);
        }
    }
    
    <!DOCTYPE html>
    <html xmlns:th="http://www.thymeleaf.org">
    ...
    
    <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>
    
    spring.thymeleaf.enabled=true 
    spring.thymeleaf.prefix=classpath:/resources/templates/ 
    
    src/main/resources/templates/index.html