【问题标题】:Using Thymeleaf templates out of the Jar file从 Jar 文件中使用 Thymeleaf 模板
【发布时间】:2016-08-28 19:07:36
【问题描述】:

我有一个使用 Thymeleaf 作为视图引擎的 Spring-boot 应用程序,我想使用部署的 Jar 之外的文件夹作为 Thymeleaf 模板的来源,我设置了变量:

spring.thymeleaf.prefix=classpath:/templates/

“/templates/”在带有 HTML 文件的 Jar 旁边,但我收到 Thymeleaf 无法解析模板的异常,我尝试了许多配置,例如:

spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.prefix=classpath:templates

等等,并非没有任何作用。我做错了什么,甚至有可能?

【问题讨论】:

    标签: java spring spring-boot thymeleaf


    【解决方案1】:

    好的,看起来这样做的方法是使用文件 url 设置值,如下所示:

    spring.thymeleaf.prefix=file:./templates/
    

    现在可以使用了。

    【讨论】:

    • 嗨,我遇到了类似的问题。只是想知道这是否是解决问题的最佳方法。将包装用作战争而不是罐子是更自然的解决方案吗?我在想象 WAR 会被提取到目录中。所以我们不必做 maven 技巧来创建两个文件。一罐。另一个/模板。有什么想法吗?
    • 使 JAR 不是 WAR
    【解决方案2】:

    spring.thymeleaf.prefix=classpath:/templates/

    returen view name 时,应该是相对路径,不能以“/”开头

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-31
      • 2020-04-07
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      • 1970-01-01
      相关资源
      最近更新 更多