diff --git a/src/asciidoc/index.adoc b/src/asciidoc/index.adoc index 2779e22b75..27ae8eb058 100644 --- a/src/asciidoc/index.adoc +++ b/src/asciidoc/index.adoc @@ -32402,6 +32402,145 @@ And the same in XML use the `` element: ---- +[[mvc-config-view-resolution]] +==== Configuring View Resolution +This is a shortcut for defining `ViewResolver` beans that can resolve views by name. + +The API allows to declare view resolvers with default values, and to customize most +useful properties. Bean name and JSP view resolvers can be declared like bellow: + +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + @Configuration + @EnableWebMvc + public class WebConfig extends WebMvcConfigurerAdapter { + + @Override + public void configureViewResolvers(ViewResolverRegistry registry) { + registry.beanName(); + registry.jsp().prefix("/"); + } + + } +---- + +And the same in XML use the `` child elements: + +[source,xml,indent=0] +[subs="verbatim,quotes"] +---- + + + + +---- + +Configuring Tiles, Velocity, FreeMarker and Groovy view resolution requires +declaring both `ViewResolver` (configured thanks to the `ViewResolverRegistry`) +and configurer beans: + +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + @Configuration + @EnableWebMvc + public class WebConfig extends WebMvcConfigurerAdapter { + + @Override + public void configureViewResolvers(ViewResolverRegistry registry) { + registry.tiles(); + registry.velocity(); + registry.freeMarker().suffix(".fmt").cache(false); + registry.groovy(); + } + + @Bean + public TilesConfigurer tilesConfigurer() { + return new TilesConfigurer(); + } + + @Bean + public VelocityConfigurer velocityConfigurer() { + return new VelocityConfigurer(); + } + + @Bean + public FreeMarkerConfigurer freeMarkerConfigurer() { + return new FreeMarkerConfigurer(); + } + + @Bean + public GroovyMarkupConfigurer groovyMarkupConfigurer() { + return new GroovyMarkupConfigurer(); + } + + } +---- + +For XML, in addition to the `` child elements, shortcut alternative +to declaring configurer beans directly are also provided: + +[source,xml,indent=0] +[subs="verbatim,quotes"] +---- + + + + + + + + + + + + + + + + + + +---- + +It is also possible to declare a `ContentNegotiatingViewResolver` bean thanks to the +`ViewResolverRegistry`. The `ContentNegotiationManager` used to determine requested media +types is configured as described in <>. +All other view resolvers declared are automatically added to the `viewResolvers` +property of the `ContentNegotiatingViewResolver` bean: + +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + @Configuration + @EnableWebMvc + public class WebConfig extends WebMvcConfigurerAdapter { + + @Override + public void configureViewResolvers(ViewResolverRegistry registry) { + registry.contentNegotiating(new MappingJackson2JsonView()); + registry.jsp(); + } + + } +---- + +And the same in XML use the `` element: + +[source,xml,indent=0] +[subs="verbatim,quotes"] +---- + + + + + + + + +---- + [[mvc-config-static-resources]] ==== Configuring Serving of Resources