相关疑难解决方法(0)

如何将 spring.freemarker.template-loader-path 指向依赖项 jar 中的模板?

我有2个项目。一个项目 (A) 包含我所有的核心功能,例如我的实体/服务/daos 等。它还包含许多我希望在我的另一个项目 (B) 中利用和重用的 .ftl 模板。我已经成功地让 (B) 使用了 (A) 中的类,但我在重用 freemarker 模板方面没有运气。

项目 (B) 是一个 Spring Boot 应用程序 (v2.1.3),所以我认为我使用 application.property: 是正确的:spring.freemarker.template-loader-path而不是定义一个新的@Bean.

由于是 spring-boot 应用程序,默认情况下,如果没有此属性,项目将在项目自己的src/main/resources/templates位置查找,但我的目标是让项目 (A) 没有自己的模板,并让我的控制器返回在其中找到的模板项目(B)。

在我的 Maven 依赖项中,层次结构是这样的:

projectA-0.0.1.jar
    templates
        folder1
            exampleA.ftl
        folder2
            exampleB.ftl
Run Code Online (Sandbox Code Playgroud)

目前,我的控制器设置为返回return new ModelAndView("folder1/exampleA")上下文前缀为 src/main/resources/templates/ 的内容

有谁知道我需要给spring.freemarker.template-loader-path属性的值的正确格式,以便指向我的依赖 jar 中的模板而不是本地 src/main/resources/templates?

dependencies freemarker external spring-boot application.properties

3
推荐指数
1
解决办法
4450
查看次数