Top Description Fields Constructors Methods
org.springframework.web.servlet.view.freemarker

public Class FreeMarkerConfigurer

extends FreeMarkerConfigurationFactory
implements FreeMarkerConfig, InitializingBean, ResourceLoaderAware
Class Inheritance
All Implemented Interfaces
org.springframework.context.ResourceLoaderAware, org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.web.servlet.view.freemarker.FreeMarkerConfig
Imports
java.io.IOException, java.util.List, freemarker.cache.ClassTemplateLoader, freemarker.cache.TemplateLoader, freemarker.template.Configuration, freemarker.template.TemplateException, org.springframework.beans.factory.InitializingBean, org.springframework.context.ResourceLoaderAware, org.springframework.lang.Nullable, org.springframework.ui.freemarker.FreeMarkerConfigurationFactory, org.springframework.util.Assert

JavaBean to configure FreeMarker for web usage, via the "configLocation" and/or "freemarkerSettings" and/or "templateLoaderPath" properties. The simplest way to use this class is to specify just a "templateLoaderPath"; you do not need any further configuration then.
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
  <property name="templateLoaderPath"><value>/WEB-INF/freemarker/</value></property>
</bean>
This bean must be included in the application context of any application using Spring's FreeMarkerView for web MVC. It exists purely to configure FreeMarker. It is not meant to be referenced by application components but just internally by FreeMarkerView. Implements FreeMarkerConfig to be found by FreeMarkerView without depending on the bean name of the configurer. Each DispatcherServlet can define its own FreeMarkerConfigurer if desired.

Note that you can also refer to a preconfigured FreeMarker Configuration instance, for example one set up by FreeMarkerConfigurationFactoryBean, via the "configuration" property. This allows to share a FreeMarker Configuration for web and email usage, for example.

This configurer registers a template loader for this package, allowing to reference the "spring.ftl" macro library contained in this package:

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

Note

Spring's FreeMarker support requires FreeMarker 2.3 or higher.

Authors
Darren Davison, Rob Harrop
Since
03.03.2004
See Also
setConfigLocation, setFreemarkerSettings, setTemplateLoaderPath, setConfiguration, org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean, FreeMarkerView

Field Summary

Modifier and TypeField and Description
private freemarker.template.Configuration
Inherited from org.springframework.ui.freemarker.FreeMarkerConfigurationFactory:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Initialize FreeMarkerConfigurationFactory's Configuration if not overridden by a preconfigured FreeMarker Configuration.

public freemarker.template.Configuration
getConfiguration()

Implements org.springframework.web.servlet.view.freemarker.FreeMarkerConfig.getConfiguration.

Return the Configuration object wrapped by this bean.

protected void
postProcessTemplateLoaders(List<freemarker.cache.TemplateLoader>
the current List of TemplateLoader instances, to be modified by a subclass
templateLoaders
)

Overrides org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.postProcessTemplateLoaders.

This implementation registers an additional ClassTemplateLoader for the Spring-provided macros, added to the end of the list.

public void
setConfiguration(freemarker.template.Configuration configuration)

Set a preconfigured Configuration to use for the FreeMarker web config, e.g. a shared one for web and email usage, set up via FreeMarkerConfigurationFactoryBean.

Inherited from org.springframework.ui.freemarker.FreeMarkerConfigurationFactory:
createConfigurationgetAggregateTemplateLoadergetResourceLoadergetTemplateLoaderForPathisPreferFileSystemAccessnewConfigurationpostProcessConfigurationsetConfigLocationsetDefaultEncodingsetFreemarkerSettingssetFreemarkerVariablessetPostTemplateLoaderssetPreferFileSystemAccesssetPreTemplateLoaderssetResourceLoadersetTemplateLoaderPathsetTemplateLoaderPaths

Field Detail

configurationback to summary
private freemarker.template.Configuration configuration
Annotations
@Nullable

Constructor Detail

FreeMarkerConfigurerback to summary
public FreeMarkerConfigurer()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws IOException, freemarker.template.TemplateException

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Initialize FreeMarkerConfigurationFactory's Configuration if not overridden by a preconfigured FreeMarker Configuration.

Sets up a ClassTemplateLoader to use for loading Spring macros.

Annotations
@Override
See Also
createConfiguration, setConfiguration
getConfigurationback to summary
public freemarker.template.Configuration getConfiguration()

Implements org.springframework.web.servlet.view.freemarker.FreeMarkerConfig.getConfiguration.

Return the Configuration object wrapped by this bean.

Returns:freemarker.template.Configuration

Doc from org.springframework.web.servlet.view.freemarker.FreeMarkerConfig.getConfiguration.

the FreeMarker Configuration

Annotations
@Override
postProcessTemplateLoadersback to summary
protected void postProcessTemplateLoaders(List<freemarker.cache.TemplateLoader> templateLoaders)

Overrides org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.postProcessTemplateLoaders.

This implementation registers an additional ClassTemplateLoader for the Spring-provided macros, added to the end of the list.

Parameters
templateLoaders:List<freemarker.cache.TemplateLoader>

Doc from org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.postProcessTemplateLoaders.

the current List of TemplateLoader instances, to be modified by a subclass

Annotations
@Override
setConfigurationback to summary
public void setConfiguration(freemarker.template.Configuration configuration)

Set a preconfigured Configuration to use for the FreeMarker web config, e.g. a shared one for web and email usage, set up via FreeMarkerConfigurationFactoryBean. If this is not set, FreeMarkerConfigurationFactory's properties (inherited by this class) have to be specified.

See Also
org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean