私は、REST要求への応答としてワイヤに置かれたPOJOのプロパティである文字列を構築する方法としてFreeMarkerを使用しています。私は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
を生成しても、構成にはまったく影響しません。
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.htmlあなたは 'spring.freemarker.template-を置くことができますloader-path = classpath:/ template /#カンマ区切りのテンプレートパスのリストをアプリのプロパティに追加します。 (または慣習に従って、sを使って 'templates'を使います) – zapl