クラス FreeMarkerConfigurer

java.lang.ObjectSE
org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer
実装されたすべてのインターフェース:
AwareInitializingBeanResourceLoaderAwareFreeMarkerConfig

public class FreeMarkerConfigurer extends FreeMarkerConfigurationFactory implements FreeMarkerConfig, InitializingBean, ResourceLoaderAware
"configLocation"、"freemarkerSettings"、"templateLoaderPath" プロパティを使用して、FreeMarker を Web 使用用に構成します。

このクラスを使用する最も簡単な方法は、"templateLoaderPath" (例: "classpath:templates" ) のみを指定することです。その場合、それ以上の設定は必要ありません。

この Bean は、FreeMarkerView を使用するアプリケーションのアプリケーションコンテキストに含める必要があります。純粋に FreeMarker を構成するために存在します。これは、アプリケーションコンポーネントによって参照されるのではなく、FreeMarkerView によって内部的に参照されるだけです。構成子の Bean 名に依存せずに、FreeMarkerView によって検出される FreeMarkerConfig を実装します。

"configuration" プロパティを介して、事前構成された FreeMarker Configuration インスタンスを参照することもできます。これにより、たとえば、Web やメールでの使用のために FreeMarker Configuration を共有できます。

このコンフィギュレーターは、このパッケージのテンプレートローダーを登録し、このパッケージに含まれる "spring.ftl" マクロライブラリを参照できるようにします。

 <#import "/spring.ftl" as spring/>
 <@spring.bind "person.age"/>
 age is ${spring.status.value}

メモ: Spring の FreeMarker サポートには FreeMarker 2.3.21 以上が必要です。

導入:
5.0
作成者:
Rossen Stoyanchev
  • コンストラクターの詳細

    • FreeMarkerConfigurer

      public FreeMarkerConfigurer()
  • メソッドの詳細

    • setConfiguration

      public void setConfiguration(freemarker.template.Configuration configuration)
      FreeMarker Web 構成に使用する事前構成済みの Configuration を設定します (たとえば、Web とメールの使用のための共有 Configuration )。

      これが設定されていない場合は、FreeMarkerConfigurationFactory のプロパティ (このクラスによって継承される) を指定する必要があります。

    • afterPropertiesSet

      public void afterPropertiesSet() throws IOExceptionSE, freemarker.template.TemplateException
      事前設定された FreeMarker Configuration によって上書きされていない場合は、FreeMarkerConfigurationFactory の Configuration を初期化します。

      Spring マクロをロードするために使用する ClassTemplateLoader を間接的に設定します。

      次で指定:
      インターフェース InitializingBeanafterPropertiesSet 
      例外:
      IOExceptionSE
      freemarker.template.TemplateException
      関連事項:
    • postProcessTemplateLoaders

      protected void postProcessTemplateLoaders(ListSE<freemarker.cache.TemplateLoader> templateLoaders)
      この実装では、Spring 提供のマクロの追加の ClassTemplateLoader が登録され、リストの最後に追加されます。
      オーバーライド:
      クラス FreeMarkerConfigurationFactorypostProcessTemplateLoaders 
      パラメーター:
      templateLoaders - サブクラスによって変更される TemplateLoader インスタンスの現在のリスト
      関連事項:
    • getConfiguration

      public freemarker.template.Configuration getConfiguration()
      この Bean でラップされた Configuration オブジェクトを返します。
      次で指定:
      インターフェース FreeMarkerConfiggetConfiguration 
      戻り値:
      FreeMarker Configuration