Remove FreeMarker/Velocity/TilesConfigurer MVC config
After some further discussion: The MVC config simplifies ViewResolver configuration especially where content negotiation view resolution is involved. The configuration of the underlying view technology however is kept completely separate. In the case of the MVC namespace, dedicated top-level freemarker, velocity, and tiles namespace elements are provided. In the case of the MVC Java config, applications simply declare FreeMarkerConfigurer, VelocityConfigurer, or TilesConfigurer beans respectively. Issue: SPR-7093
This commit is contained in:
@@ -53,24 +53,6 @@ public class ViewResolutionIntegrationTests {
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void minimalFreemarkerConfig() throws Exception {
|
||||
MockHttpServletResponse response = runTest(MinimalFreeMarkerWebConfig.class);
|
||||
assertEquals("<html><body>Hello World!</body></html>", response.getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void minimalVelocityConfig() throws Exception {
|
||||
MockHttpServletResponse response = runTest(MinimalVelocityWebConfig.class);
|
||||
assertEquals("<html><body>Hello World!</body></html>", response.getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void minimalTilesConfig() throws Exception {
|
||||
MockHttpServletResponse response = runTest(MinimalTilesWebConfig.class);
|
||||
assertEquals("/WEB-INF/index.jsp", response.getForwardedUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freemarker() throws Exception {
|
||||
MockHttpServletResponse response = runTest(FreeMarkerWebConfig.class);
|
||||
@@ -91,19 +73,19 @@ public class ViewResolutionIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void freemarkerInvalidConfig() throws Exception {
|
||||
this.thrown.expectMessage("It looks like you're trying to configure FreeMarker view resolution.");
|
||||
this.thrown.expectMessage("In addition to a FreeMarker view resolver ");
|
||||
runTest(InvalidFreeMarkerWebConfig.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void velocityInvalidConfig() throws Exception {
|
||||
this.thrown.expectMessage("It looks like you're trying to configure Velocity view resolution.");
|
||||
this.thrown.expectMessage("In addition to a Velocity view resolver ");
|
||||
runTest(InvalidVelocityWebConfig.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tilesInvalidConfig() throws Exception {
|
||||
this.thrown.expectMessage("It looks like you're trying to configure Tiles view resolution.");
|
||||
this.thrown.expectMessage("In addition to a Tiles view resolver ");
|
||||
runTest(InvalidTilesWebConfig.class);
|
||||
}
|
||||
|
||||
@@ -138,6 +120,7 @@ public class ViewResolutionIntegrationTests {
|
||||
|
||||
@EnableWebMvc
|
||||
static abstract class AbstractWebConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
public SampleController sampleController() {
|
||||
return new SampleController();
|
||||
@@ -145,69 +128,56 @@ public class ViewResolutionIntegrationTests {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class MinimalFreeMarkerWebConfig extends AbstractWebConfig {
|
||||
static class FreeMarkerWebConfig extends AbstractWebConfig {
|
||||
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.freeMarker();
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class MinimalVelocityWebConfig extends AbstractWebConfig {
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.velocity();
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class MinimalTilesWebConfig extends AbstractWebConfig {
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.tiles();
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class FreeMarkerWebConfig extends AbstractWebConfig implements FreeMarkerWebMvcConfigurer {
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.freeMarker();
|
||||
}
|
||||
@Override
|
||||
public void configureFreeMarker(FreeMarkerConfigurer configurer) {
|
||||
@Bean
|
||||
public FreeMarkerConfigurer freeMarkerConfigurer() {
|
||||
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
|
||||
configurer.setTemplateLoaderPath("/WEB-INF/");
|
||||
return configurer;
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class VelocityWebConfig extends AbstractWebConfig implements VelocityWebMvcConfigurer {
|
||||
static class VelocityWebConfig extends AbstractWebConfig {
|
||||
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.velocity();
|
||||
}
|
||||
@Override
|
||||
public void configureVelocity(VelocityConfigurer configurer) {
|
||||
|
||||
@Bean
|
||||
public VelocityConfigurer velocityConfigurer() {
|
||||
VelocityConfigurer configurer = new VelocityConfigurer();
|
||||
configurer.setResourceLoaderPath("/WEB-INF/");
|
||||
return configurer;
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class TilesWebConfig extends AbstractWebConfig implements TilesWebMvcConfigurer {
|
||||
static class TilesWebConfig extends AbstractWebConfig {
|
||||
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.tiles();
|
||||
}
|
||||
@Override
|
||||
public void configureTiles(TilesConfigurer configurer) {
|
||||
|
||||
@Bean
|
||||
public TilesConfigurer tilesConfigurer() {
|
||||
TilesConfigurer configurer = new TilesConfigurer();
|
||||
configurer.setDefinitions("/WEB-INF/tiles.xml");
|
||||
return configurer;
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class InvalidFreeMarkerWebConfig extends WebMvcConfigurationSupport {
|
||||
|
||||
// No @EnableWebMvc and no FreeMarkerConfigurer bean
|
||||
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.freeMarker();
|
||||
@@ -217,8 +187,6 @@ public class ViewResolutionIntegrationTests {
|
||||
@Configuration
|
||||
static class InvalidVelocityWebConfig extends WebMvcConfigurationSupport {
|
||||
|
||||
// No @EnableWebMvc and no VelocityConfigurer bean
|
||||
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.velocity();
|
||||
@@ -228,8 +196,6 @@ public class ViewResolutionIntegrationTests {
|
||||
@Configuration
|
||||
static class InvalidTilesWebConfig extends WebMvcConfigurationSupport {
|
||||
|
||||
// No @EnableWebMvc and no TilesConfigurer bean
|
||||
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.tiles();
|
||||
|
||||
Reference in New Issue
Block a user