Class FreeMarkerConfigurer
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.InitializingBean,org.springframework.context.ResourceLoaderAware,org.springframework.web.context.ServletContextAware,FreeMarkerConfig
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 pre-configured FreeMarker Configuration
instance 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.33 or higher.
- Since:
- 03.03.2004
- Author:
- Darren Davison, Rob Harrop
- See Also:
-
FreeMarkerConfigurationFactory.setConfigLocation(org.springframework.core.io.Resource)FreeMarkerConfigurationFactory.setFreemarkerSettings(java.util.Properties)FreeMarkerConfigurationFactory.setTemplateLoaderPath(java.lang.String)setConfiguration(freemarker.template.Configuration)FreeMarkerConfigurationFactoryBeanFreeMarkerView
-
Field Summary
Fields inherited from class org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInitialize FreeMarkerConfigurationFactory'sConfigurationif not overridden by a preconfigured FreeMarkerConfiguration.freemarker.template.ConfigurationReturn theConfigurationobject wrapped by this bean.freemarker.ext.jakarta.jsp.TaglibFactoryReturn the TaglibFactory object wrapped by this bean.protected voidpostProcessTemplateLoaders(List<freemarker.cache.TemplateLoader> templateLoaders) This implementation registers an additionalClassTemplateLoaderfor the Spring-provided macros, added to the end of the list.voidsetConfiguration(freemarker.template.Configuration configuration) Set a preconfiguredConfigurationto use for the FreeMarker web config — for example, a shared one for web and email usage.voidsetServletContext(ServletContext servletContext) Initialize theTaglibFactoryfor the given ServletContext.Methods inherited from class org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
createConfiguration, getAggregateTemplateLoader, getResourceLoader, getTemplateLoaderForPath, isPreferFileSystemAccess, newConfiguration, postProcessConfiguration, setConfigLocation, setDefaultCharset, setDefaultEncoding, setFreemarkerSettings, setFreemarkerVariables, setPostTemplateLoaders, setPreferFileSystemAccess, setPreTemplateLoaders, setResourceLoader, setTemplateLoaderPath, setTemplateLoaderPathsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ResourceLoaderAware
setResourceLoader
-
Constructor Details
-
FreeMarkerConfigurer
public FreeMarkerConfigurer()
-
-
Method Details
-
setConfiguration
public void setConfiguration(freemarker.template.Configuration configuration) Set a preconfiguredConfigurationto use for the FreeMarker web config — for example, a shared one for web and email usage.If this is not set, FreeMarkerConfigurationFactory's properties (inherited by this class) have to be specified.
- See Also:
-
FreeMarkerConfigurationFactoryBean
-
setServletContext
Initialize theTaglibFactoryfor the given ServletContext.- Specified by:
setServletContextin interfaceorg.springframework.web.context.ServletContextAware
-
afterPropertiesSet
Initialize FreeMarkerConfigurationFactory'sConfigurationif not overridden by a preconfigured FreeMarkerConfiguration.Indirectly sets up a
ClassTemplateLoaderto use for loading Spring macros.- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
IOExceptionfreemarker.template.TemplateException- See Also:
-
FreeMarkerConfigurationFactory.createConfiguration()setConfiguration(freemarker.template.Configuration)postProcessTemplateLoaders(List)
-
postProcessTemplateLoaders
This implementation registers an additionalClassTemplateLoaderfor the Spring-provided macros, added to the end of the list.- Overrides:
postProcessTemplateLoadersin classorg.springframework.ui.freemarker.FreeMarkerConfigurationFactory
-
getConfiguration
public freemarker.template.Configuration getConfiguration()Return theConfigurationobject wrapped by this bean.- Specified by:
getConfigurationin interfaceFreeMarkerConfig- Returns:
- the FreeMarker
Configuration
-
getTaglibFactory
public freemarker.ext.jakarta.jsp.TaglibFactory getTaglibFactory()Return the TaglibFactory object wrapped by this bean.- Specified by:
getTaglibFactoryin interfaceFreeMarkerConfig
-