Add support for using Velocity templates
This commit is contained in:
@@ -94,6 +94,7 @@ content into your application; rather pick only the properties that you need.
|
||||
spring.freemarker.exposeSpringMacroHelpers=false
|
||||
spring.freemarker.prefix=
|
||||
spring.freemarker.requestContextAttribute=
|
||||
spring.freemarker.settings.*=
|
||||
spring.freemarker.suffix=.ftl
|
||||
spring.freemarker.templateEncoding=UTF-8
|
||||
spring.freemarker.templateLoaderPath=classpath:/templates/
|
||||
@@ -103,17 +104,36 @@ content into your application; rather pick only the properties that you need.
|
||||
spring.groovy.template.allowRequestOverride=false
|
||||
spring.groovy.template.allowSessionOverride=false
|
||||
spring.groovy.template.cache=true
|
||||
spring.groovy.template.configuration.*= # See Groovy's TemplateConfiguration
|
||||
spring.groovy.template.contentType=text/html
|
||||
spring.groovy.template.prefix=classpath:/templates/
|
||||
spring.groovy.template.suffix=.tpl
|
||||
spring.groovy.template.templateEncoding=UTF-8
|
||||
spring.groovy.template.viewNames= # whitelist of view names that can be resolved
|
||||
spring.groovy.template.configuration.*= # See Groovy's TemplateConfiguration
|
||||
|
||||
# VELOCITY TEMPLATES ({sc-spring-boot-autoconfigure}}/velocity/VelocityAutoConfiguration.{sc-ext}[VelocityAutoConfiguration])
|
||||
spring.velocity.allowRequestOverride=false
|
||||
spring.velocity.allowSessionOverride=false
|
||||
spring.velocity.cache=true
|
||||
spring.velocity.checkTemplateLocation=true
|
||||
spring.velocity.contentType=text/html
|
||||
spring.velocity.dateToolAttribute=
|
||||
spring.velocity.exposeRequestAttributes=false
|
||||
spring.velocity.exposeSessionAttributes=false
|
||||
spring.velocity.exposeSpringMacroHelpers=false
|
||||
spring.velocity.numberToolAttribute=
|
||||
spring.velocity.prefix=
|
||||
spring.velocity.properties.*=
|
||||
spring.velocity.requestContextAttribute=
|
||||
spring.velocity.resourceLoaderPath=classpath:/templates/
|
||||
spring.velocity.suffix=.ftl
|
||||
spring.velocity.templateEncoding=UTF-8
|
||||
spring.velocity.viewNames= # whitelist of view names that can be resolved
|
||||
|
||||
# INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/MessageSourceAutoConfiguration.{sc-ext}[MessageSourceAutoConfiguration])
|
||||
spring.messages.basename=messages
|
||||
spring.messages.cacheSeconds=-1
|
||||
spring.messages.encoding=UTF-8
|
||||
spring.messages.cacheSeconds=-1
|
||||
|
||||
[[common-application-properties-security]]
|
||||
# SECURITY ({sc-spring-boot-autoconfigure}/security/SecurityProperties.{sc-ext}[SecurityProperties])
|
||||
|
||||
@@ -41,6 +41,9 @@ The following auto-configuration classes are from the `spring-boot-autoconfigure
|
||||
|{sc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{sc-ext}[FreeMarkerAutoConfiguration]
|
||||
|{dc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{dc-ext}[javadoc]
|
||||
|
||||
|{sc-spring-boot-autoconfigure}/groovy/templates/GroovyTemplateAutoConfiguration.{sc-ext}[GroovyTemplateAutoConfiguration]
|
||||
|{dc-spring-boot-autoconfigure}/groovy/templates/GroovyTemplateAutoConfiguration.{dc-ext}[javadoc]
|
||||
|
||||
|{sc-spring-boot-autoconfigure}/orm/jpa/HibernateJpaAutoConfiguration.{sc-ext}[HibernateJpaAutoConfiguration]
|
||||
|{dc-spring-boot-autoconfigure}/orm/jpa/HibernateJpaAutoConfiguration.{dc-ext}[javadoc]
|
||||
|
||||
@@ -95,6 +98,9 @@ The following auto-configuration classes are from the `spring-boot-autoconfigure
|
||||
|{sc-spring-boot-autoconfigure}/thymeleaf/ThymeleafAutoConfiguration.{sc-ext}[ThymeleafAutoConfiguration]
|
||||
|{dc-spring-boot-autoconfigure}/thymeleaf/ThymeleafAutoConfiguration.{dc-ext}[javadoc]
|
||||
|
||||
|{sc-spring-boot-autoconfigure}/velocity/VelocityAutoConfiguration.{sc-ext}[VelocityAutoConfiguration]
|
||||
|{dc-spring-boot-autoconfigure}/velocity/VelocityAutoConfiguration.{dc-ext}[javadoc]
|
||||
|
||||
|{sc-spring-boot-autoconfigure}/web/WebMvcAutoConfiguration.{sc-ext}[WebMvcAutoConfiguration]
|
||||
|{dc-spring-boot-autoconfigure}/web/WebMvcAutoConfiguration.{dc-ext}[javadoc]
|
||||
|
||||
|
||||
@@ -813,20 +813,28 @@ added.
|
||||
``freeMarkerViewResolver''. It looks for resources in a loader path (externalized to
|
||||
`spring.freemarker.templateLoaderPath`, default ``classpath:/templates/'') by
|
||||
surrounding the view name with a prefix and suffix (externalized to `spring.freemarker.prefix`
|
||||
and `spring.freemarker.suffix`, defaults ``'' and ``.ftl'' respectively). It can be overriden
|
||||
and `spring.freemarker.suffix`, with empty and ``.ftl'' defaults respectively). It can be overriden
|
||||
by providing a bean of the same name.
|
||||
|
||||
* If you use Groovy templates (actually if groovy-templates is on your classpath) you
|
||||
also have a `Groovy TemplateViewResolver` with id
|
||||
* If you use Groovy templates (actually if groovy-templates is on your classpath) you will
|
||||
also have a `Groovy TemplateViewResolver` with id
|
||||
``groovyTemplateViewResolver''. It looks for resources in a loader path by
|
||||
surrounding the view name with a prefix and suffix (externalized to `spring.groovy.template.prefix`
|
||||
and `spring.groovy.template.suffix`, defaults ``classpath:/templates/'' and ``.tpl'' respectively). It can be overriden
|
||||
by providing a bean of the same name.
|
||||
surrounding the view name with a prefix and suffix (externalized to
|
||||
`spring.groovy.template.prefix` and `spring.groovy.template.suffix`, defaults
|
||||
``classpath:/templates/'' and ``.tpl'' respectively). It can be overriden by providing a bean of
|
||||
the same name.
|
||||
|
||||
* If you use Velocity you will also have a `VelocityViewResolver` with id ``velocityViewResolver''.
|
||||
It looks for resources in a loader path (externalized to `spring.velocity.resourceLoaderPath`,
|
||||
default ``classpath:/templates/'') by surrounding the view name with a prefix and suffix
|
||||
(externalized to `spring.velocity.prefix' and `spring.velocity.suffix`, with empty and ``.vm''
|
||||
defaults respectively). It can be overridden by providing a bean of the same name.
|
||||
|
||||
Check out {sc-spring-boot-autoconfigure}/web/WebMvcAutoConfiguration.{sc-ext}[`WebMvcAutoConfiguration`],
|
||||
{sc-spring-boot-autoconfigure}/thymeleaf/ThymeleafAutoConfiguration.{sc-ext}[`ThymeleafAutoConfiguration`],
|
||||
{sc-spring-boot-autoconfigure}/groovy/template/GroovyTemplateAutoConfiguration.{sc-ext}['GroovyTemplateAutoConfiguration'] and
|
||||
{sc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{sc-ext}['FreeMarkerAutoConfiguration']
|
||||
{sc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{sc-ext}[`FreeMarkerAutoConfiguration`],
|
||||
{sc-spring-boot-autoconfigure}/groovy/template/GroovyTemplateAutoConfiguration.{sc-ext}[`GroovyTemplateAutoConfiguration`] and
|
||||
{sc-spring-boot-autoconfigure}/velocity/VelocityAutoConfiguration.{sc-ext}[`VelocityAutoConfiguration`]
|
||||
|
||||
|
||||
|
||||
@@ -1279,12 +1287,13 @@ The Actuator installs a ``whitelabel'' error page that you will see in browser c
|
||||
you encounter a server error (machine clients consuming JSON and other media types should
|
||||
see a sensible response with the right error code). To switch it off you can set
|
||||
`error.whitelabel.enabled=false`, but normally in addition or alternatively to that you
|
||||
will want to add your own error page replacing the whitelabel one. If you are using
|
||||
Thymeleaf or FreeMarker you can do this by adding an `error.html` or `error.ftl` template
|
||||
respectively. In general what you need is a `View` that resolves with a name of `error`,
|
||||
and/or a `@Controller` that handles the `/error` path. Unless you replaced some of the
|
||||
default configuration you should find a `BeanNameViewResolver` in your `ApplicationContext`
|
||||
so a `@Bean` with id `error` would be a simple way of doing that.
|
||||
will want to add your own error page replacing the whitelabel one. Exactly how you do this
|
||||
dependns on the templating technology that you are using. For example, if you are using
|
||||
Thymeleaf you would add an `error.html` template and if you are using FreeMarker you would
|
||||
add an `error.ftl` template. In general what you need is a `View` that resolves with a name
|
||||
of `error`, and/or a `@Controller` that handles the `/error` path. Unless you replaced some
|
||||
of the default configuration you should find a `BeanNameViewResolver` in your
|
||||
`ApplicationContext` so a `@Bean` with id `error` would be a simple way of doing that.
|
||||
Look at {sc-spring-boot-autoconfigure}/web/ErrorMvcAutoConfiguration.{sc-ext}[`ErrorMvcAutoConfiguration`] for more options.
|
||||
|
||||
|
||||
@@ -1403,6 +1412,13 @@ If you are using Groovy templates, then set `spring.groovy.template.cache` to `f
|
||||
for other Groovy customization options.
|
||||
|
||||
|
||||
[[howto-reload-velocity-content]]
|
||||
=== Reload Velocity templates without restarting the container
|
||||
If you are using Velocity, then set `spring.velocity.cache` to `false`. See
|
||||
{sc-spring-boot-autoconfigure}/velocity/VelocityAutoConfiguration.{sc-ext}[`VelocityAutoConfiguration`]
|
||||
for other Velocity customization options.
|
||||
|
||||
|
||||
[[howto-reload-java-classes-without-restarting]]
|
||||
=== Reload Java classes without restarting the container
|
||||
Modern IDEs (Eclipse, IDEA, etc.) all support hot swapping of bytecode, so if you make a
|
||||
|
||||
@@ -906,27 +906,26 @@ and it will be silently ignored by most build tools if you generate a jar.
|
||||
[[boot-features-spring-mvc-template-engines]]
|
||||
==== Template engines
|
||||
|
||||
As well as REST web services, you can also use Spring MVC to serve
|
||||
dynamic HTML content. Spring MVC supports a variety of templating
|
||||
technologies including: Velocity, FreeMarker and JSPs. Many
|
||||
As well as REST web services, you can also use Spring MVC to serve dynamic HTML content. Spring
|
||||
MVC supports a variety of templating technologies including Velocity, FreeMarker and JSPs. Many
|
||||
other templating engines also ship their own Spring MVC integrations.
|
||||
|
||||
Spring Boot includes auto-configuration support for the Thymeleaf,
|
||||
[FreeMarker](http://freemarker.org/docs/) and
|
||||
[Groovy](http://beta.groovy-lang.org/docs/groovy-2.3.0/html/documentation/markup-template-engine.html)
|
||||
templating engines. Thymeleaf is an XML/XHTML/HTML5 template engine
|
||||
that can work both in web and non-web environments. If allows you to
|
||||
create natural templates that can be correctly displayed by browsers
|
||||
and therefore work also as static prototypes. Your FreeMarker, Groovy
|
||||
and Thymeleaf templates will be picked up automatically from
|
||||
`src/main/resources/templates`.
|
||||
Spring Boot includes auto-configuration support for the following templating engines:
|
||||
|
||||
- http://freemarker.org/docs/[FreeMarker]
|
||||
- http://beta.groovy-lang.org/docs/groovy-2.3.0/html/documentation/markup-template-engine.html[Groovy]
|
||||
- http://www.thymeleaf.org[Thymeleaf]
|
||||
- http://velocity.apache.org[Velocity]
|
||||
|
||||
When you're using one of these templating engines with the default configuration, your templates
|
||||
will be picked up automatically from `src/main/resources/templates`.
|
||||
|
||||
TIP: JSPs should be avoided if possible, there are several
|
||||
<<boot-features-jsp-limitations, known limitations>> when using them with embedded
|
||||
servlet containers.
|
||||
|
||||
|
||||
|
||||
[[boot-features-error-handling]]
|
||||
==== Error Handling
|
||||
Spring Boot provides an `/error` mapping by default that handles all errors in a
|
||||
|
||||
@@ -258,6 +258,9 @@ and Hibernate.
|
||||
|`spring-boot-starter-thymeleaf`
|
||||
|Support for the Thymeleaf templating engine, including integration with Spring.
|
||||
|
||||
|`spring-boot-starter-velocity`
|
||||
|Support for the Velocity templating engine
|
||||
|
||||
|`spring-boot-starter-web`
|
||||
|Support for full-stack web development, including Tomcat and `spring-webmvc`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user