【问题标题】:giving Freemarker resource folder in deployed application for spring boot在部署的应用程序中为 Spring Boot 提供 Freemarker 资源文件夹
【发布时间】:2020-10-12 21:29:24
【问题描述】:

我正在尝试为下面的 Freemarker 模板提供资源文件夹是我的 bean 配置

 配置 freeMarkerConfig() 抛出 IOException {
    配置 cfg = 新配置(Configuration.VERSION_2_3_29);
    cfg.setDirectoryForTemplateLoading(new ClassPathResource("ftl").getFile());
    返回配置文件;
  }

我在资源文件夹中有 ftl 文件夹

   -- java
   -- resources
       -- ftl
           -- template.ftl

虽然部署它在我的本地机器上运行良好,但在我的 docker 容器中失败并出现异常

java.io.FileNotFoundException: class path resource [ftl] cannot be resolved to absolute file
 path because it does not reside in the file system: jar:file:!/BOOT-INF/classes!/ftl

我需要将 ftl 保存在资源文件夹中,并给出配置的目录路径。我不知道如何进一步调试。

【问题讨论】:

    标签: spring-boot freemarker


    【解决方案1】:

    spring.freemarker.template-loader-path 属性可用。

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

    或者,使用setTemplateLoaderPath("classpath:/ftl/") 代替setDirectoryForTemplateLoading()

    【讨论】:

    • 我在 freemarker.template.Configuration java 类中没有看到这个方法
    【解决方案2】:

    我反复搜索后发现了这个问题。问题是因为这个

    Classpath resource not found when running as jar

    【讨论】:

      猜你喜欢
      • 2020-11-30
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      • 2017-06-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 2018-12-28
      相关资源
      最近更新 更多