public class FreeMarkerConfigurer extends org.springframework.ui.freemarker.FreeMarkerConfigurationFactory implements FreeMarkerConfig, org.springframework.beans.factory.InitializingBean, org.springframework.context.ResourceLoaderAware, org.springframework.web.context.ServletContextAware
<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 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 and thus in spring.jar) like this:
<#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.FreeMarkerConfigurationFactory.setConfigLocation(org.springframework.core.io.Resource),
FreeMarkerConfigurationFactory.setFreemarkerSettings(java.util.Properties),
FreeMarkerConfigurationFactory.setTemplateLoaderPath(java.lang.String),
setConfiguration(freemarker.template.Configuration),
FreeMarkerConfigurationFactoryBean,
FreeMarkerView| Constructor and Description |
|---|
FreeMarkerConfigurer() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Initialize FreeMarkerConfigurationFactory's Configuration
if not overridden by a preconfigured FreeMarker Configuation.
|
freemarker.template.Configuration |
getConfiguration()
Return the Configuration object wrapped by this bean.
|
freemarker.ext.jsp.TaglibFactory |
getTaglibFactory()
Return the TaglibFactory object wrapped by this bean.
|
protected void |
postProcessTemplateLoaders(List<freemarker.cache.TemplateLoader> templateLoaders)
This implementation registers an additional ClassTemplateLoader
for the Spring-provided macros, added to the end of the list.
|
void |
setConfiguration(freemarker.template.Configuration configuration)
Set a preconfigured Configuration to use for the FreeMarker web config, e.g.
|
void |
setServletContext(ServletContext servletContext)
Initialize the
TaglibFactory for the given ServletContext. |
createConfiguration, getAggregateTemplateLoader, getResourceLoader, getTemplateLoaderForPath, isPreferFileSystemAccess, newConfiguration, postProcessConfiguration, setConfigLocation, setDefaultEncoding, setFreemarkerSettings, setFreemarkerVariables, setPostTemplateLoaders, setPreferFileSystemAccess, setPreTemplateLoaders, setResourceLoader, setTemplateLoaderPath, setTemplateLoaderPathspublic void setConfiguration(freemarker.template.Configuration configuration)
FreeMarkerConfigurationFactoryBeanpublic void setServletContext(ServletContext servletContext)
TaglibFactory for the given ServletContext.setServletContext in interface org.springframework.web.context.ServletContextAwarepublic void afterPropertiesSet()
throws IOException,
freemarker.template.TemplateException
Sets up a ClassTemplateLoader to use for loading Spring macros.
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanIOExceptionfreemarker.template.TemplateExceptionFreeMarkerConfigurationFactory.createConfiguration(),
setConfiguration(freemarker.template.Configuration)protected void postProcessTemplateLoaders(List<freemarker.cache.TemplateLoader> templateLoaders)
postProcessTemplateLoaders in class org.springframework.ui.freemarker.FreeMarkerConfigurationFactorypublic freemarker.template.Configuration getConfiguration()
getConfiguration in interface FreeMarkerConfigpublic freemarker.ext.jsp.TaglibFactory getTaglibFactory()
getTaglibFactory in interface FreeMarkerConfig