spring-framework / org.springframework.web.servlet.view.groovy / GroovyMarkupConfigurer

GroovyMarkupConfigurer

open class GroovyMarkupConfigurer : TemplateConfiguration, GroovyMarkupConfig, ApplicationContextAware, InitializingBean

An extension of Groovy's groovy.text.markup.TemplateConfiguration and an implementation of Spring MVC's GroovyMarkupConfig for creating a MarkupTemplateEngine for use in a web application. The most basic way to configure this class is to set the "resourceLoaderPath". For example:

 // Add the following to an @Configuration class @Bean public GroovyMarkupConfig groovyMarkupConfigurer() { GroovyMarkupConfigurer configurer = new GroovyMarkupConfigurer(); configurer.setResourceLoaderPath("classpath:/WEB-INF/groovymarkup/"); return configurer; } 
By default this bean will create a MarkupTemplateEngine with: You can provide the MarkupTemplateEngine instance directly to this bean in which case all other properties will not be effectively ignored.

This bean must be included in the application context of any application using the Spring MVC GroovyMarkupView for rendering. It exists purely for the purpose of configuring Groovy's Markup templates. It is not meant to be referenced by application components directly. It implements GroovyMarkupConfig to be found by GroovyMarkupView without depending on a bean name. Each DispatcherServlet can define its own GroovyMarkupConfigurer if desired.

Note that resource caching is enabled by default in MarkupTemplateEngine. Use the #setCacheTemplates(boolean) to configure that as necessary.

Spring's Groovy Markup template support requires Groovy 2.3.1 or higher.

Author
Brian Clozel

Author
Rossen Stoyanchev

Since
4.1

See Also
GroovyMarkupView<a href="http://groovy-lang.org/templating.html#_the_markuptemplateengine">

Constructors

<init>

GroovyMarkupConfigurer()

An extension of Groovy's groovy.text.markup.TemplateConfiguration and an implementation of Spring MVC's GroovyMarkupConfig for creating a MarkupTemplateEngine for use in a web application. The most basic way to configure this class is to set the "resourceLoaderPath". For example:

 // Add the following to an @Configuration class @Bean public GroovyMarkupConfig groovyMarkupConfigurer() { GroovyMarkupConfigurer configurer = new GroovyMarkupConfigurer(); configurer.setResourceLoaderPath("classpath:/WEB-INF/groovymarkup/"); return configurer; } 
By default this bean will create a MarkupTemplateEngine with:
  • a parent ClassLoader for loading Groovy templates with their references
  • the default configuration in the base class TemplateConfiguration
  • a groovy.text.markup.TemplateResolver for resolving template files
You can provide the MarkupTemplateEngine instance directly to this bean in which case all other properties will not be effectively ignored.

This bean must be included in the application context of any application using the Spring MVC GroovyMarkupView for rendering. It exists purely for the purpose of configuring Groovy's Markup templates. It is not meant to be referenced by application components directly. It implements GroovyMarkupConfig to be found by GroovyMarkupView without depending on a bean name. Each DispatcherServlet can define its own GroovyMarkupConfigurer if desired.

Note that resource caching is enabled by default in MarkupTemplateEngine. Use the #setCacheTemplates(boolean) to configure that as necessary.

Spring's Groovy Markup template support requires Groovy 2.3.1 or higher.

Functions

afterPropertiesSet

open fun afterPropertiesSet(): Unit

getResourceLoaderPath

open fun getResourceLoaderPath(): String

getTemplateEngine

open fun getTemplateEngine(): MarkupTemplateEngine

setApplicationContext

open fun setApplicationContext(applicationContext: ApplicationContext): Unit

setLocale

open fun setLocale(locale: Locale): Unit

This method should not be used, since the considered Locale for resolving templates is the Locale for the current HTTP request.

setResourceLoaderPath

open fun setResourceLoaderPath(resourceLoaderPath: String): Unit

Set the Groovy Markup Template resource loader path(s) via a Spring resource location. Accepts multiple locations as a comma-separated list of paths. Standard URLs like "file:" and "classpath:" and pseudo URLs are supported as understood by Spring's org.springframework.core.io.ResourceLoader. Relative paths are allowed when running in an ApplicationContext.

setTemplateEngine

open fun setTemplateEngine(templateEngine: MarkupTemplateEngine): Unit

Set a pre-configured MarkupTemplateEngine to use for the Groovy Markup Template web configuration.

Note that this engine instance has to be manually configured, since all other bean properties of this configurer will be ignored.