diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java index fe246232b7..c2eb2391ac 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java @@ -51,7 +51,7 @@ import static org.mockito.Mockito.*; * @author Sebastien Deleuze */ @RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration("src/test/resources/META-INF/web-resources") +@WebAppConfiguration("classpath:META-INF/web-resources") @ContextHierarchy({ @ContextConfiguration(classes = RootConfig.class), @ContextConfiguration(classes = WebConfig.class) @@ -100,7 +100,7 @@ public class JavaConfigTests { @Configuration @EnableWebMvc - static class WebConfig extends WebMvcConfigurerAdapter implements TilesWebMvcConfigurer { + static class WebConfig extends WebMvcConfigurerAdapter { @Autowired private RootConfig rootConfig; @@ -130,9 +130,11 @@ public class JavaConfigTests { registry.tiles(); } - @Override - public void configureTiles(TilesConfigurer configurer) { + @Bean + public TilesConfigurer tilesConfigurer() { + TilesConfigurer configurer = new TilesConfigurer(); configurer.setDefinitions("/WEB-INF/**/tiles.xml"); + return configurer; } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java index ec699fc621..c3b39b7b5e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java @@ -33,10 +33,6 @@ import org.springframework.context.annotation.Import; * } * * - *
As of 4.1 this annotation may also import {@link WebMvcFreeMarkerConfiguration}, - * {@link WebMvcVelocityConfiguration}, or {@link WebMvcTilesConfiguration} if - * those libraries are found on the classpath. - * *
To customize the imported configuration, implement the interface * {@link WebMvcConfigurer} or more likely extend the empty method base class * {@link WebMvcConfigurerAdapter} and override individual methods, e.g.: @@ -61,10 +57,6 @@ import org.springframework.context.annotation.Import; * } * * - *
To customize the FreeMarker, Velocity, or Tiles configuration, additionally - * implement {@link FreeMarkerWebMvcConfigurer}, {@link VelocityWebMvcConfigurer}, - * and/or {@link TilesWebMvcConfigurer}. - * *
If {@link WebMvcConfigurer} does not expose some advanced setting that * needs to be configured, consider removing the {@code @EnableWebMvc} * annotation and extending directly from {@link WebMvcConfigurationSupport}, e.g.: @@ -87,23 +79,15 @@ import org.springframework.context.annotation.Import; * } * * - *
When the {@code @EnableWebMvc} annotation is removed, the FreeMarker, - * Velocity, and Tiles configuration is no longer automatically imported and need - * to be imported explicitly. - * * @author Dave Syer * @author Rossen Stoyanchev - * @author Sebastien Deleuze * @since 3.1 * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurer * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter - * @see org.springframework.web.servlet.config.annotation.FreeMarkerWebMvcConfigurer - * @see org.springframework.web.servlet.config.annotation.VelocityWebMvcConfigurer - * @see org.springframework.web.servlet.config.annotation.TilesWebMvcConfigurer */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Documented -@Import({DelegatingWebMvcConfiguration.class, ViewConfigurationImportSelector.class}) +@Import({DelegatingWebMvcConfiguration.class}) public @interface EnableWebMvc { } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/FreeMarkerWebMvcConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/FreeMarkerWebMvcConfigurer.java deleted file mode 100644 index 5ac4b893bc..0000000000 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/FreeMarkerWebMvcConfigurer.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.web.servlet.config.annotation; - -import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; - -/** - * Defines a callback method to customize the - * {@link org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer - * FreeMarkerConfigurer} bean provided when using {@code @EnableWebMvc}. - * - *
An {@code @EnableWebMvc}-annotated configuration classes can implement - * this interface to customize the {@code FreeMarkerConfigurer}. - * - * @author Rossen Stoyanchev - * @since 4.1 - */ -public interface FreeMarkerWebMvcConfigurer { - - void configureFreeMarker(FreeMarkerConfigurer configurer); - -} diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/TilesWebMvcConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/TilesWebMvcConfigurer.java deleted file mode 100644 index f2f9d62ce8..0000000000 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/TilesWebMvcConfigurer.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.web.servlet.config.annotation; - -import org.springframework.web.servlet.view.tiles3.TilesConfigurer; - -/** - * Defines a callback method to customize the - * {@link org.springframework.web.servlet.view.tiles3.TilesConfigurer - * TilesConfigurer} bean provided when using {@code @EnableWebMvc}. - * - *
An {@code @EnableWebMvc}-annotated configuration classes can implement - * this interface to customize the {@code TilesConfigurer}. - * - * @author Rossen Stoyanchev - * @since 4.1 - */ -public interface TilesWebMvcConfigurer { - - void configureTiles(TilesConfigurer configurer); - -} diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/VelocityWebMvcConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/VelocityWebMvcConfigurer.java deleted file mode 100644 index 0887e0b966..0000000000 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/VelocityWebMvcConfigurer.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.web.servlet.config.annotation; - -import org.springframework.web.servlet.view.velocity.VelocityConfigurer; - -/** - * Defines a callback method to customize the - * {@link org.springframework.web.servlet.view.velocity.VelocityConfigurer - * VelocityConfigurer} bean provided when using {@code @EnableWebMvc}. - * - *
An {@code @EnableWebMvc}-annotated configuration classes can implement
- * this interface to customize the {@code VelocityConfigurer}.
- *
- * @author Rossen Stoyanchev
- * @since 4.1
- */
-public interface VelocityWebMvcConfigurer {
-
- void configureVelocity(VelocityConfigurer configurer);
-
-}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewConfigurationImportSelector.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewConfigurationImportSelector.java
deleted file mode 100644
index 379e92eb30..0000000000
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewConfigurationImportSelector.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.web.servlet.config.annotation;
-
-import org.springframework.context.annotation.DeferredImportSelector;
-import org.springframework.core.type.AnnotationMetadata;
-import org.springframework.util.ClassUtils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Selectively imports configuration required to configure Tiles, Freemarker, or
- * Velocity for view resolution depending on whether those 3rd party libraries
- * are available on the classpath.
- *
- * @author Sebastien Deleuze
- * @author Rossen Stoyanchev
- * @since 4.1
- *
- * @see WebMvcFreeMarkerConfiguration
- */
-public class ViewConfigurationImportSelector implements DeferredImportSelector {
-
- private static final boolean tilesPresent = ClassUtils.isPresent(
- "org.apache.tiles.startup.TilesInitializer", ViewConfigurationImportSelector.class.getClassLoader());
-
- private static final boolean velocityPresent = ClassUtils.isPresent(
- "org.apache.velocity.app.VelocityEngine", ViewConfigurationImportSelector.class.getClassLoader());
-
- private static final boolean freeMarkerPresent = ClassUtils.isPresent(
- "freemarker.template.Configuration", ViewConfigurationImportSelector.class.getClassLoader());
-
-
- @Override
- public String[] selectImports(AnnotationMetadata importingClassMetadata) {
- List This method may be invoked multiple and each call will register a
- * separate ViewResolver instance. Note that since it's not easy to determine
+ * When this method is invoked more than once, each call will register a
+ * new ViewResolver instance. Note that since it's not easy to determine
* if a JSP exists without forwarding to it, using multiple JSP-based view
* resolvers only makes sense in combination with the "viewNames" property
- * that indicates which view names are handled by which resolver.
+ * on the resolver indicating which view names are handled by which resolver.
*/
public UrlBasedViewResolverRegistration jsp() {
return jsp("/WEB-INF/", ".jsp");
}
/**
- * Enable view resolution by forwarding to JSP pages with the specified
- * prefix and suffix.
+ * Register JSP view resolver with the specified prefix and suffix.
*
- * This method may be invoked multiple and each call will register a
- * separate ViewResolver instance. Note that since it's not easy to determine
+ * When this method is invoked more than once, each call will register a
+ * new ViewResolver instance. Note that since it's not easy to determine
* if a JSP exists without forwarding to it, using multiple JSP-based view
* resolvers only makes sense in combination with the "viewNames" property
- * that indicates which view names are handled by which resolver.
+ * on the resolver indicating which view names are handled by which resolver.
*/
public UrlBasedViewResolverRegistration jsp(String prefix, String suffix) {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
@@ -162,18 +161,16 @@ public class ViewResolverRegistry {
}
/**
- * Enable Tiles-based view resolution.
+ * Register Tiles 3.x view resolver.
*
- * By default tiles definitions are expected to be in "/WEB-INF/tiles.xml".
- * To change that and other Tiles-related options please also implement the
- * interface {@link TilesWebMvcConfigurer}.
+ * Note that you must also configure Tiles by adding a
+ * {@link org.springframework.web.servlet.view.tiles3.TilesConfigurer} bean.
*/
public UrlBasedViewResolverRegistration tiles() {
if (this.applicationContext != null && !hasBeanOfType(TilesConfigurer.class)) {
- throw new BeanInitializationException(
- "It looks like you're trying to configure Tiles view resolution. " +
- "If not using @EnableWebMvc you must import WebMvcTilesConfiguration, " +
- "or declare your own TilesConfigurer bean.");
+ throw new BeanInitializationException("In addition to a Tiles view resolver " +
+ "there must also be a single TilesConfigurer bean in this web application context " +
+ "(or its parent).");
}
TilesRegistration registration = new TilesRegistration();
this.viewResolvers.add(registration.getViewResolver());
@@ -181,19 +178,18 @@ public class ViewResolverRegistry {
}
/**
- * Enable FreeMarker-based view resolution with an empty default view name
+ * Register a FreeMarker view resolver with an empty default view name
* prefix and a default suffix of ".ftl".
*
- * By default the FreeMarker template loader path is set to "/WEB-INF/".
- * To change that and other FreeMarker-related options please also implement
- * the interface {@link FreeMarkerWebMvcConfigurer}.
+ * Note that you must also configure FreeMarker by adding a
+ * {@link org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer} bean.
*/
public UrlBasedViewResolverRegistration freeMarker() {
if (this.applicationContext != null && !hasBeanOfType(FreeMarkerConfigurer.class)) {
- throw new BeanInitializationException(
- "It looks like you're trying to configure FreeMarker view resolution. " +
- "If not using @EnableWebMvc you must import WebMvcFreeMarkerConfiguration, " +
- "or declare your own FreeMarkerConfigurer bean.");
+ throw new BeanInitializationException("In addition to a FreeMarker view resolver " +
+ "there must also be a single FreeMarkerConfig bean in this web application context " +
+ "(or its parent): FreeMarkerConfigurer is the usual implementation. " +
+ "This bean may be given any name.");
}
FreeMarkerRegistration registration = new FreeMarkerRegistration();
this.viewResolvers.add(registration.getViewResolver());
@@ -201,19 +197,18 @@ public class ViewResolverRegistry {
}
/**
- * Enable Velocity-based view resolution with an empty default view name
+ * Register Velocity view resolver with an empty default view name
* prefix, a default suffix of ".vm".
*
- * By default the Velocity resource loader path is set to "/WEB-INF/".
- * To change that and other Velocity-related options please also implement
- * the interface {@link VelocityWebMvcConfigurer}.
+ * Note that you must also configure Velocity by adding a
+ * {@link org.springframework.web.servlet.view.velocity.VelocityConfigurer} bean.
*/
public UrlBasedViewResolverRegistration velocity() {
if (this.applicationContext != null && !hasBeanOfType(VelocityConfigurer.class)) {
- throw new BeanInitializationException(
- "It looks like you're trying to configure Velocity view resolution. " +
- "If not using @EnableWebMvc you must import WebMvcVelocityConfiguration, " +
- "or declare your own VelocityConfigurer bean.");
+ throw new BeanInitializationException("In addition to a Velocity view resolver " +
+ "there must also be a single VelocityConfig bean in this web application context " +
+ "(or its parent): VelocityConfigurer is the usual implementation. " +
+ "This bean may be given any name.");
}
VelocityRegistration registration = new VelocityRegistration();
this.viewResolvers.add(registration.getViewResolver());
@@ -221,8 +216,8 @@ public class ViewResolverRegistry {
}
/**
- * Enable the ability to map view names returned from controllers to
- * {@link org.springframework.web.servlet.View} beans.
+ * Register a bean name view resolver that interprets view names as the names
+ * of {@link org.springframework.web.servlet.View} beans.
*/
public void beanName() {
BeanNameViewResolver resolver = new BeanNameViewResolver();
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcFreeMarkerConfiguration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcFreeMarkerConfiguration.java
deleted file mode 100644
index da1af95545..0000000000
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcFreeMarkerConfiguration.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.web.servlet.config.annotation;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.util.CollectionUtils;
-import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Configuration class that declares a
- * {@link org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
- * FreeMarkerConfigurer} bean. The configuration is conditional and applies
- * only if there is no {@code FreeMarkerConfigurer} bean already declared.
- *
- * This configuration is imported when using {@link EnableWebMvc} if
- * FreeMarker is available on the classpath. It can be customized by
- * implementing {@link FreeMarkerWebMvcConfigurer}.
- *
- * @author Rossen Stoyanchev
- * @since 4.1
- */
-@Configuration
-@Conditional(WebMvcFreeMarkerConfiguration.FreeMarkerConfigurerNotPresentCondition.class)
-public class WebMvcFreeMarkerConfiguration {
-
- private final List This configuration is imported when using {@link EnableWebMvc} if Tiles 3
- * is available on the classpath. It can be customized by implementing
- * {@link TilesWebMvcConfigurer}.
- *
- * @author Rossen Stoyanchev
- * @since 4.1
- */
-@Configuration
-@Conditional(WebMvcTilesConfiguration.TilesConfigurerNotPresentCondition.class)
-public class WebMvcTilesConfiguration implements ResourceLoaderAware {
-
- private final List This configuration is imported when using {@link EnableWebMvc} if
- * Velocity is available on the classpath. It can be customized by
- * implementing {@link VelocityWebMvcConfigurer}.
- *
- * @author Rossen Stoyanchev
- * @since 4.1
- */
-@Configuration
-@Conditional(WebMvcVelocityConfiguration.VelocityConfigurerNotPresentCondition.class)
-public class WebMvcVelocityConfiguration {
-
- private final List