2016-05-13 39 views
1

私は、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を生成しても、構成にはまったく影響しません。

+0

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.htmlあなたは 'spring.freemarker.template-を置くことができますloader-path = classpath:/ template /#カンマ区切りのテンプレートパスのリストをアプリのプロパティに追加します。 (または慣習に従って、sを使って 'templates'を使います) – zapl

答えて

0

http://freemarker.org/docs/pgui_config_templateloading.html

あなたはSRC /メイン/リソース/テンプレートフォルダ内のFTLテンプレートを置くことができ、それが自動的に無料のマーカーバージョンのために認識されます:春ブーツに2.3.26-インキュベート。それ以外の場合は、application.propertiesファイルで以下のコードを使用し、使用されている場所でオブジェクトをautowireします。

spring.freemarker.template-loader-path=relativefolder/ 

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

関連する問題