Spring 引导无法从 cmd 找到可执行 jar 中的 ftl 文件

Spring Boot is unable to locate ftl files in executable jar from cmd

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Cannot find template location(s): [ServletContext resource [/templates]] (please add some templates, check your FreeMarker configuration, or set spring.freemarker.checkTemplateLocation=false)

我将 ftl 文件保存在资源的模板文件夹中。

在application.properties中我也添加了这些行

spring.freemarker.template-loader-path=/templates

您已覆盖默认 Spring 启动 属性 值:

spring.freemarker.template-loader-path=classpath:/templates

现在您指向一个文件系统目录/templates。删除自定义 属性 以从默认类路径位置加载 FTL 文件。