Skip to content

Commit 05fb37d

Browse files
snicollphilwebb
authored andcommitted
Adapt to Spring MVC API updates
See gh-45487
1 parent c15418b commit 05fb37d

File tree

8 files changed

+3
-165
lines changed

8 files changed

+3
-165
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/CompositeHandlerAdapter.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,14 +60,6 @@ public ModelAndView handle(HttpServletRequest request, HttpServletResponse respo
6060
return null;
6161
}
6262

63-
@Override
64-
@Deprecated(since = "2.4.9", forRemoval = false)
65-
@SuppressWarnings("deprecation")
66-
public long getLastModified(HttpServletRequest request, Object handler) {
67-
Optional<HandlerAdapter> adapter = getAdapter(handler);
68-
return adapter.map((handlerAdapter) -> handlerAdapter.getLastModified(request, handler)).orElse(0L);
69-
}
70-
7163
private Optional<HandlerAdapter> getAdapter(Object handler) {
7264
if (this.adapters == null) {
7365
this.adapters = extractAdapters();

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java

-5
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,6 @@ protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handler
249249
return null;
250250
}
251251

252-
@Override
253-
protected void extendInterceptors(List<Object> interceptors) {
254-
interceptors.add(new SkipPathExtensionContentNegotiation());
255-
}
256-
257252
/**
258253
* Return the Handler providing actuator links at the root endpoint.
259254
* @return the links handler

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMapping.java

-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.EnumSet;
2323
import java.util.HashSet;
2424
import java.util.LinkedHashMap;
25-
import java.util.List;
2625
import java.util.Map;
2726
import java.util.Set;
2827

@@ -163,9 +162,4 @@ protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
163162
return this.corsConfiguration;
164163
}
165164

166-
@Override
167-
protected void extendInterceptors(List<Object> interceptors) {
168-
interceptors.add(new SkipPathExtensionContentNegotiation());
169-
}
170-
171165
}

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/SkipPathExtensionContentNegotiation.java

-44
This file was deleted.

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/RequestMappingConditionsDescription.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,6 +70,7 @@ public class RequestMappingConditionsDescription {
7070
.toList();
7171
}
7272

73+
@SuppressWarnings("removal")
7374
private Set<String> extractPathPatterns(RequestMappingInfo requestMapping) {
7475
PatternsRequestCondition patternsCondition = requestMapping.getPatternsCondition();
7576
return (patternsCondition != null) ? patternsCondition.getPatterns()

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java

-59
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.time.Duration;
2020
import java.util.List;
21-
import java.util.ListIterator;
2221
import java.util.Map;
2322
import java.util.function.Consumer;
2423

@@ -80,13 +79,9 @@
8079
import org.springframework.validation.DefaultMessageCodesResolver;
8180
import org.springframework.validation.MessageCodesResolver;
8281
import org.springframework.validation.Validator;
83-
import org.springframework.web.HttpMediaTypeNotAcceptableException;
8482
import org.springframework.web.accept.ContentNegotiationManager;
85-
import org.springframework.web.accept.ContentNegotiationStrategy;
8683
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
8784
import org.springframework.web.context.ServletContextAware;
88-
import org.springframework.web.context.request.NativeWebRequest;
89-
import org.springframework.web.context.request.RequestAttributes;
9085
import org.springframework.web.context.request.RequestContextListener;
9186
import org.springframework.web.context.support.ServletContextResource;
9287
import org.springframework.web.filter.FormContentFilter;
@@ -459,15 +454,6 @@ public LocaleResolver localeResolver() {
459454
return localeResolver;
460455
}
461456

462-
@Override
463-
@Bean
464-
@ConditionalOnMissingBean(name = DispatcherServlet.THEME_RESOLVER_BEAN_NAME)
465-
@Deprecated(since = "3.0.0", forRemoval = false)
466-
@SuppressWarnings("deprecation")
467-
public org.springframework.web.servlet.ThemeResolver themeResolver() {
468-
return super.themeResolver();
469-
}
470-
471457
@Override
472458
@Bean
473459
@ConditionalOnMissingBean(name = DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME)
@@ -580,22 +566,6 @@ protected void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> ex
580566
}
581567
}
582568

583-
@Bean
584-
@Override
585-
@SuppressWarnings("deprecation")
586-
public ContentNegotiationManager mvcContentNegotiationManager() {
587-
ContentNegotiationManager manager = super.mvcContentNegotiationManager();
588-
List<ContentNegotiationStrategy> strategies = manager.getStrategies();
589-
ListIterator<ContentNegotiationStrategy> iterator = strategies.listIterator();
590-
while (iterator.hasNext()) {
591-
ContentNegotiationStrategy strategy = iterator.next();
592-
if (strategy instanceof org.springframework.web.accept.PathExtensionContentNegotiationStrategy) {
593-
iterator.set(new OptionalPathExtensionContentNegotiationStrategy(strategy));
594-
}
595-
}
596-
return manager;
597-
}
598-
599569
@Override
600570
public void setResourceLoader(ResourceLoader resourceLoader) {
601571
this.resourceLoader = resourceLoader;
@@ -683,33 +653,4 @@ ProblemDetailsExceptionHandler problemDetailsExceptionHandler() {
683653

684654
}
685655

686-
/**
687-
* Decorator to make
688-
* {@link org.springframework.web.accept.PathExtensionContentNegotiationStrategy}
689-
* optional depending on a request attribute.
690-
*/
691-
static class OptionalPathExtensionContentNegotiationStrategy implements ContentNegotiationStrategy {
692-
693-
@SuppressWarnings("deprecation")
694-
private static final String SKIP_ATTRIBUTE = org.springframework.web.accept.PathExtensionContentNegotiationStrategy.class
695-
.getName() + ".SKIP";
696-
697-
private final ContentNegotiationStrategy delegate;
698-
699-
OptionalPathExtensionContentNegotiationStrategy(ContentNegotiationStrategy delegate) {
700-
this.delegate = delegate;
701-
}
702-
703-
@Override
704-
public List<MediaType> resolveMediaTypes(NativeWebRequest webRequest)
705-
throws HttpMediaTypeNotAcceptableException {
706-
Object skip = webRequest.getAttribute(SKIP_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
707-
if (skip != null && Boolean.parseBoolean(skip.toString())) {
708-
return MEDIA_TYPE_ALL_LIST;
709-
}
710-
return this.delegate.resolveMediaTypes(webRequest);
711-
}
712-
713-
}
714-
715656
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfigurationTests.java

-9
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,6 @@ void dispatcherServletDefaultConfig() {
158158
});
159159
}
160160

161-
@Test
162-
@Deprecated(since = "3.2.0", forRemoval = true)
163-
void dispatcherServletThrowExceptionIfNoHandlerFoundDefaultConfig() {
164-
this.contextRunner.run((context) -> {
165-
DispatcherServlet dispatcherServlet = context.getBean(DispatcherServlet.class);
166-
assertThat(dispatcherServlet).extracting("throwExceptionIfNoHandlerFound").isEqualTo(true);
167-
});
168-
}
169-
170161
@Test
171162
void dispatcherServletCustomConfig() {
172163
this.contextRunner

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java

-32
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
import org.springframework.web.servlet.View;
111111
import org.springframework.web.servlet.ViewResolver;
112112
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
113-
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
114113
import org.springframework.web.servlet.config.annotation.CorsRegistry;
115114
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
116115
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
@@ -865,16 +864,6 @@ void usePathPatternParser() {
865864
});
866865
}
867866

868-
@Test
869-
void defaultContentNegotiation() {
870-
this.contextRunner.run((context) -> {
871-
RequestMappingHandlerMapping handlerMapping = context.getBean(RequestMappingHandlerMapping.class);
872-
ContentNegotiationManager contentNegotiationManager = handlerMapping.getContentNegotiationManager();
873-
assertThat(contentNegotiationManager.getStrategies()).doesNotHaveAnyElementsOfTypes(
874-
WebMvcAutoConfiguration.OptionalPathExtensionContentNegotiationStrategy.class);
875-
});
876-
}
877-
878867
@Test
879868
void queryParameterContentNegotiation() {
880869
this.contextRunner.withPropertyValues("spring.mvc.contentnegotiation.favor-parameter:true").run((context) -> {
@@ -885,16 +874,6 @@ void queryParameterContentNegotiation() {
885874
});
886875
}
887876

888-
@Test
889-
void customConfigurerAppliedAfterAutoConfig() {
890-
this.contextRunner.withUserConfiguration(CustomConfigurer.class).run((context) -> {
891-
ContentNegotiationManager manager = context.getBean(ContentNegotiationManager.class);
892-
assertThat(manager.getStrategies())
893-
.anyMatch((strategy) -> WebMvcAutoConfiguration.OptionalPathExtensionContentNegotiationStrategy.class
894-
.isAssignableFrom(strategy.getClass()));
895-
});
896-
}
897-
898877
@Test
899878
void requestContextFilterIsAutoConfigured() {
900879
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(RequestContextFilter.class));
@@ -1324,17 +1303,6 @@ HttpMessageConverter<?> customHttpMessageConverter(ConversionService conversionS
13241303

13251304
}
13261305

1327-
@Configuration(proxyBeanMethods = false)
1328-
static class CustomConfigurer implements WebMvcConfigurer {
1329-
1330-
@Override
1331-
@SuppressWarnings("deprecation")
1332-
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
1333-
configurer.favorPathExtension(true);
1334-
}
1335-
1336-
}
1337-
13381306
@Configuration(proxyBeanMethods = false)
13391307
static class CustomApplicationTaskExecutorConfig {
13401308

0 commit comments

Comments
 (0)