Consistent configurer access in WebMvcConfigurationSupport

Issue: SPR-16017

(cherry picked from commit 40ba95f)
This commit is contained in:
Juergen Hoeller
2017-09-27 19:00:51 +02:00
parent 00c0d7847f
commit a1a7c62127
12 changed files with 104 additions and 97 deletions

View File

@@ -40,6 +40,7 @@ import org.springframework.web.context.request.NativeWebRequest;
* {@code MediaTypeFileExtensionResolver} instances.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 3.2
*/
public class ContentNegotiationManager implements ContentNegotiationStrategy, MediaTypeFileExtensionResolver {
@@ -66,6 +67,7 @@ public class ContentNegotiationManager implements ContentNegotiationStrategy, Me
* A collection-based alternative to
* {@link #ContentNegotiationManager(ContentNegotiationStrategy...)}.
* @param strategies the strategies to use
* @since 3.2.2
*/
public ContentNegotiationManager(Collection<ContentNegotiationStrategy> strategies) {
Assert.notEmpty(strategies, "At least one ContentNegotiationStrategy is expected");
@@ -96,7 +98,7 @@ public class ContentNegotiationManager implements ContentNegotiationStrategy, Me
/**
* Find a {@code ContentNegotiationStrategy} of the given type.
* @param strategyType the strategy type
* @return the first matching strategy or {@code null}.
* @return the first matching strategy, or {@code null} if none
* @since 4.3
*/
@SuppressWarnings("unchecked")

View File

@@ -86,6 +86,7 @@ import org.springframework.web.context.ServletContextAware;
* {@link #setStrategies(List)}.
*
* @author Rossen Stoyanchev
* @author Brian Clozel
* @since 3.2
*/
public class ContentNegotiationManagerFactoryBean
@@ -293,6 +294,10 @@ public class ContentNegotiationManagerFactoryBean
build();
}
/**
* Actually build the {@link ContentNegotiationManager}.
* @since 5.0
*/
public ContentNegotiationManager build() {
List<ContentNegotiationStrategy> strategies = new ArrayList<>();
@@ -303,8 +308,7 @@ public class ContentNegotiationManagerFactoryBean
if (this.favorPathExtension) {
PathExtensionContentNegotiationStrategy strategy;
if (this.servletContext != null && !useRegisteredExtensionsOnly()) {
strategy = new ServletPathExtensionContentNegotiationStrategy(
this.servletContext, this.mediaTypes);
strategy = new ServletPathExtensionContentNegotiationStrategy(this.servletContext, this.mediaTypes);
}
else {
strategy = new PathExtensionContentNegotiationStrategy(this.mediaTypes);
@@ -317,14 +321,13 @@ public class ContentNegotiationManagerFactoryBean
}
if (this.favorParameter) {
ParameterContentNegotiationStrategy strategy =
new ParameterContentNegotiationStrategy(this.mediaTypes);
ParameterContentNegotiationStrategy strategy = new ParameterContentNegotiationStrategy(this.mediaTypes);
strategy.setParameterName(this.parameterName);
if (this.useRegisteredExtensionsOnly != null) {
strategy.setUseRegisteredExtensionsOnly(this.useRegisteredExtensionsOnly);
}
else {
strategy.setUseRegisteredExtensionsOnly(true); // backwards compatibility
strategy.setUseRegisteredExtensionsOnly(true); // backwards compatibility
}
strategies.add(strategy);
}