2016-05-13 98 views
1

我使用FreeMarker作爲構建字符串的一種方式,這是作爲對REST請求的響應放置在線上的POJO的屬性。我已經將Freemarker添加到項目的Maven pom中,我可以將配置注入到我的服務中,但爲了讓類加載器找到我的模板,我必須做一件特別的事情。Spring Boot + FreeMarker + RestController加載模板

 private Template getTemplate() throws Exception { 
     configuration.setClassForTemplateLoading(this.getClass(), "/template/"); 

     Template temp = configuration.getTemplate("test.ftl"); 

     return temp; 
    } 

是否有更簡潔的方式來配置FreeMarker尋找模板的位置?使用@Bean生成FreeMarkerConfigurer完全不影響配置。

+0

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html你可以把'spring.freemarker.template- loader-path = classpath:/ template /#逗號分隔的模板路徑列表到您的應用程序屬性中。 (或者堅持慣例,並使用's模板') – zapl

回答