open class FreeMarkerConfigurationFactory
Factory that configures a FreeMarker Configuration. Can be used standalone, but typically you will either use FreeMarkerConfigurationFactoryBean for preparing a Configuration as bean reference, or FreeMarkerConfigurer for web views.
The optional "configLocation" property sets the location of a FreeMarker properties file, within the current application. FreeMarker properties can be overridden via "freemarkerSettings". All of these properties will be set by calling FreeMarker's Configuration.setSettings()
method and are subject to constraints set by FreeMarker.
The "freemarkerVariables" property can be used to specify a Map of shared variables that will be applied to the Configuration via the setAllSharedVariables()
method. Like setSettings()
, these entries are subject to FreeMarker constraints.
The simplest way to use this class is to specify a "templateLoaderPath"; FreeMarker does not need any further configuration then.
Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher.
Author
Darren Davison
Author
Juergen Hoeller
Since
03.03.2004
See Also
#setConfigLocation#setFreemarkerSettings#setFreemarkerVariables#setTemplateLoaderPath#createConfigurationFreeMarkerConfigurationFactoryBeanorg.springframework.web.servlet.view.freemarker.FreeMarkerConfigurerfreemarker.template.Configuration
FreeMarkerConfigurationFactory()
Factory that configures a FreeMarker Configuration. Can be used standalone, but typically you will either use FreeMarkerConfigurationFactoryBean for preparing a Configuration as bean reference, or FreeMarkerConfigurer for web views. The optional "configLocation" property sets the location of a FreeMarker properties file, within the current application. FreeMarker properties can be overridden via "freemarkerSettings". All of these properties will be set by calling FreeMarker's The "freemarkerVariables" property can be used to specify a Map of shared variables that will be applied to the Configuration via the The simplest way to use this class is to specify a "templateLoaderPath"; FreeMarker does not need any further configuration then. Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher. |
open fun createConfiguration(): Configuration
Prepare the FreeMarker Configuration and return it. |
|
open fun setConfigLocation(resource: Resource): Unit
Set the location of the FreeMarker config file. Alternatively, you can specify all setting locally. |
|
open fun setDefaultEncoding(defaultEncoding: String): Unit
Set the default encoding for the FreeMarker configuration. If not specified, FreeMarker will use the platform file encoding. Used for template rendering unless there is an explicit encoding specified for the rendering process (for example, on Spring's FreeMarkerView). |
|
open fun setFreemarkerSettings(settings: Properties): Unit
Set properties that contain well-known FreeMarker keys which will be passed to FreeMarker's |
|
open fun setFreemarkerVariables(variables: MutableMap<String, Any>): Unit
Set a Map that contains well-known FreeMarker objects which will be passed to FreeMarker's |
|
open fun setPostTemplateLoaders(vararg postTemplateLoaders: TemplateLoader): Unit
Set a List of The TemplateLoader specified here will be registered after the default template loaders that this factory registers (such as loaders for specified "templateLoaderPaths" or any loaders registered in |
|
open fun setPreTemplateLoaders(vararg preTemplateLoaders: TemplateLoader): Unit
Set a List of The TemplateLoader specified here will be registered before the default template loaders that this factory registers (such as loaders for specified "templateLoaderPaths" or any loaders registered in |
|
open fun setPreferFileSystemAccess(preferFileSystemAccess: Boolean): Unit
Set whether to prefer file system access for template loading. File system access enables hot detection of template changes. If this is enabled, FreeMarkerConfigurationFactory will try to resolve the specified "templateLoaderPath" as file system resource (which will work for expanded class path resources and ServletContext resources too). Default is "true". Turn this off to always load via SpringTemplateLoader (i.e. as stream, without hot detection of template changes), which might be necessary if some of your templates reside in an expanded classes directory while others reside in jar files. |
|
open fun setResourceLoader(resourceLoader: ResourceLoader): Unit
Set the Spring ResourceLoader to use for loading FreeMarker template files. The default is DefaultResourceLoader. Will get overridden by the ApplicationContext if running in a context. |
|
open fun setTemplateLoaderPath(templateLoaderPath: String): Unit
Set the Freemarker template loader path via a Spring resource location. See the "templateLoaderPaths" property for details on path handling. |
|
open fun setTemplateLoaderPaths(vararg templateLoaderPaths: String): Unit
Set multiple Freemarker template loader paths via Spring resource locations. When populated via a String, standard URLs like "file:" and "classpath:" pseudo URLs are supported, as understood by ResourceEditor. Allows for relative paths when running in an ApplicationContext. Will define a path for the default FreeMarker template loader. If a specified resource cannot be resolved to a To enforce the use of SpringTemplateLoader, i.e. to not resolve a path as file system resource in any case, turn off the "preferFileSystemAccess" flag. See the latter's javadoc for details. If you wish to specify your own list of TemplateLoaders, do not set this property and instead use |
open class FreeMarkerConfigurationFactoryBean : FreeMarkerConfigurationFactory, FactoryBean<Configuration>, InitializingBean, ResourceLoaderAware
Factory bean that creates a FreeMarker Configuration and provides it as bean reference. This bean is intended for any kind of usage of FreeMarker in application code, e.g. for generating email content. For web views, FreeMarkerConfigurer is used to set up a FreeMarkerConfigurationFactory. The simplest way to use this class is to specify just a "templateLoaderPath"; you do not need any further configuration then. For example, in a web application context: See the base class FreeMarkerConfigurationFactory for configuration details.
Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher. |
|
open class FreeMarkerConfigurer : FreeMarkerConfigurationFactory, FreeMarkerConfig, InitializingBean, ResourceLoaderAware, ServletContextAware
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. 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: Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher.
|