Support Java and MVC namespace view resolution config

This commit improves and completes the initial MVC namespace
view resolution implementation. ContentNegotiatingViewResolver
registration is now also supported.

Java Config view resolution support has been added.
FreeMarker, Velocity and Tiles view configurers are registered
depending on the classpath thanks to an ImportSelector.

For both, a default configuration is provided and documented.

Issue: SPR-7093
This commit is contained in:
Sebastien Deleuze
2014-06-19 11:40:14 +02:00
committed by Rossen Stoyanchev
parent a26b1ef8d9
commit cc7e8f5558
34 changed files with 1995 additions and 263 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,14 +34,7 @@ import org.springframework.test.web.servlet.samples.context.JavaConfigTests.Root
import org.springframework.test.web.servlet.samples.context.JavaConfigTests.WebConfig;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesView;
import org.springframework.web.servlet.config.annotation.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
@@ -54,6 +47,7 @@ import static org.mockito.Mockito.*;
*
* @author Rossen Stoyanchev
* @author Sam Brannen
* @author Sebastien Deleuze
*/
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration("src/test/resources/META-INF/web-resources")
@@ -130,19 +124,11 @@ public class JavaConfigTests {
configurer.enable();
}
@Bean
public UrlBasedViewResolver urlBasedViewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setViewClass(TilesView.class);
return resolver;
@Override
public void configureViewResolution(ViewResolutionRegistry registry) {
registry.tiles().definition("/WEB-INF/**/tiles.xml");
}
@Bean
public TilesConfigurer tilesConfigurer() {
TilesConfigurer configurer = new TilesConfigurer();
configurer.setDefinitions(new String[] {"/WEB-INF/**/tiles.xml"});
return configurer;
}
}
}

View File

@@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolutionRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.util.UriComponentsBuilder;
@@ -94,6 +95,11 @@ public class EncodedUriTests {
public HandlerMappingConfigurer myHandlerMappingConfigurer() {
return new HandlerMappingConfigurer();
}
@Override
public void configureViewResolution(ViewResolutionRegistry registry) {
registry.jsp("", "");
}
}
@Controller