diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java index e3d4f45aaef..dbbb46635d8 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java @@ -59,12 +59,9 @@ import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.handler.MatchableHandlerMapping; import org.springframework.web.servlet.handler.RequestMatchResult; -import org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition; -import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition; -import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition; -import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition; import org.springframework.web.servlet.mvc.method.RequestMappingInfo; import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; +import org.springframework.web.util.UrlPathHelper; /** * A custom {@link HandlerMapping} that makes {@link ExposableWebEndpoint web endpoints} @@ -161,7 +158,6 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin @SuppressWarnings("deprecation") private static RequestMappingInfo.BuilderConfiguration getBuilderConfig() { RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration(); - config.setUrlPathHelper(null); config.setPathMatcher(null); config.setSuffixPatternMatch(false); config.setTrailingSlashMatch(true); @@ -195,34 +191,21 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin } private RequestMappingInfo createRequestMappingInfo(WebOperationRequestPredicate predicate, String path) { - PatternsRequestCondition patterns = patternsRequestConditionForPattern(path); - RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition( - RequestMethod.valueOf(predicate.getHttpMethod().name())); - ConsumesRequestCondition consumes = new ConsumesRequestCondition( - StringUtils.toStringArray(predicate.getConsumes())); - ProducesRequestCondition produces = new ProducesRequestCondition( - StringUtils.toStringArray(predicate.getProduces())); - return new RequestMappingInfo(null, patterns, methods, null, null, consumes, produces, null); + return RequestMappingInfo.paths(this.endpointMapping.createSubPath(path)) + .methods(RequestMethod.valueOf(predicate.getHttpMethod().name())) + .consumes(predicate.getConsumes().toArray(new String[0])) + .produces(predicate.getProduces().toArray(new String[0])).build(); } private void registerLinksMapping() { - PatternsRequestCondition patterns = patternsRequestConditionForPattern(""); - RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition(RequestMethod.GET); - ProducesRequestCondition produces = new ProducesRequestCondition(this.endpointMediaTypes.getProduced() - .toArray(StringUtils.toStringArray(this.endpointMediaTypes.getProduced()))); - RequestMappingInfo mapping = new RequestMappingInfo(patterns, methods, null, null, null, produces, null); + RequestMappingInfo mapping = RequestMappingInfo.paths(this.endpointMapping.createSubPath("")) + .methods(RequestMethod.GET).produces(this.endpointMediaTypes.getProduced().toArray(new String[0])) + .options(builderConfig).build(); LinksHandler linksHandler = getLinksHandler(); registerMapping(mapping, linksHandler, ReflectionUtils.findMethod(linksHandler.getClass(), "links", HttpServletRequest.class, HttpServletResponse.class)); } - @SuppressWarnings("deprecation") - private PatternsRequestCondition patternsRequestConditionForPattern(String path) { - String[] patterns = new String[] { this.endpointMapping.createSubPath(path) }; - return new PatternsRequestCondition(patterns, builderConfig.getUrlPathHelper(), builderConfig.getPathMatcher(), - builderConfig.useSuffixPatternMatch(), builderConfig.useTrailingSlashMatch()); - } - @Override protected boolean hasCorsConfigurationSource(Object handler) { return this.corsConfiguration != null; @@ -332,7 +315,7 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin } private Object getRemainingPathSegments(HttpServletRequest request) { - String[] pathTokens = tokenize(request, HandlerMapping.LOOKUP_PATH, true); + String[] pathTokens = tokenize(request, UrlPathHelper.PATH_ATTRIBUTE, true); String[] patternTokens = tokenize(request, HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, false); int numberOfRemainingPathSegments = pathTokens.length - patternTokens.length + 1; Assert.state(numberOfRemainingPathSegments >= 0, "Unable to extract remaining path segments"); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/SkipPathExtensionContentNegotiation.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/SkipPathExtensionContentNegotiation.java index 9aa78891802..156ee979962 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/SkipPathExtensionContentNegotiation.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/SkipPathExtensionContentNegotiation.java @@ -19,16 +19,16 @@ package org.springframework.boot.actuate.endpoint.web.servlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import org.springframework.web.servlet.HandlerInterceptor; /** - * {@link HandlerInterceptorAdapter} to ensure that + * {@link HandlerInterceptor} to ensure that * {@link org.springframework.web.accept.PathExtensionContentNegotiationStrategy} is * skipped for web endpoints. * * @author Phillip Webb */ -final class SkipPathExtensionContentNegotiation extends HandlerInterceptorAdapter { +final class SkipPathExtensionContentNegotiation implements HandlerInterceptor { @SuppressWarnings("deprecation") private static final String SKIP_ATTRIBUTE = org.springframework.web.accept.PathExtensionContentNegotiationStrategy.class diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/MvcWebEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/MvcWebEndpointIntegrationTests.java index 9ff0ed2fcb1..1c4bda2425b 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/MvcWebEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/MvcWebEndpointIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -121,6 +121,13 @@ class MvcWebEndpointIntegrationTests context.register(TestEndpointConfiguration.class); context.refresh(); WebMvcEndpointHandlerMapping bean = context.getBean(WebMvcEndpointHandlerMapping.class); + try { + // Trigger initLookupPath + bean.getHandler(request); + } + catch (Exception ex) { + throw new RuntimeException(ex); + } return bean.match(request, "/spring"); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/StaticResourceRequest.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/StaticResourceRequest.java index 04f9baa1123..9d6b71c1226 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/StaticResourceRequest.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/StaticResourceRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -128,7 +128,8 @@ public final class StaticResourceRequest { } private Stream getPatterns() { - return this.locations.stream().flatMap(StaticResourceLocation::getPatterns); + return this.locations.stream().flatMap(StaticResourceLocation::getPatterns) + .map((pattern) -> pattern.replace("/**/", "/*/")); } @Override diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java index 92dcd200130..fa4d733b90c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java @@ -284,18 +284,6 @@ public class WebMvcAutoConfiguration { return resolver; } - @Bean - @ConditionalOnMissingBean - @ConditionalOnProperty(prefix = "spring.mvc", name = "locale") - public LocaleResolver localeResolver() { - if (this.mvcProperties.getLocaleResolver() == WebMvcProperties.LocaleResolver.FIXED) { - return new FixedLocaleResolver(this.mvcProperties.getLocale()); - } - AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver(); - localeResolver.setDefaultLocale(this.mvcProperties.getLocale()); - return localeResolver; - } - @Override public MessageCodesResolver getMessageCodesResolver() { if (this.mvcProperties.getMessageCodesResolverFormat() != null) { @@ -420,6 +408,19 @@ public class WebMvcAutoConfiguration { return welcomePageHandlerMapping; } + @Override + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty(prefix = "spring.mvc", name = "locale", matchIfMissing = true) + public LocaleResolver localeResolver() { + if (this.mvcProperties.getLocaleResolver() == WebMvcProperties.LocaleResolver.FIXED) { + return new FixedLocaleResolver(this.mvcProperties.getLocale()); + } + AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver(); + localeResolver.setDefaultLocale(this.mvcProperties.getLocale()); + return localeResolver; + } + private Optional getWelcomePage() { String[] locations = getResourceLocations(this.resourceProperties.getStaticLocations()); return Arrays.stream(locations).map(this::getIndexHtml).filter(this::isReadable).findFirst(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java index ee97b1330d2..9871c6aa0a5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java @@ -28,6 +28,7 @@ import org.springframework.boot.web.codec.CodecCustomizer; import org.springframework.boot.web.reactive.function.client.WebClientCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.client.reactive.ClientHttpResponse; @@ -87,6 +88,7 @@ class WebClientAutoConfigurationTests { void shouldGetPrototypeScopedBean() { this.contextRunner.withUserConfiguration(WebClientCustomizerConfig.class).run((context) -> { ClientHttpResponse response = mock(ClientHttpResponse.class); + given(response.getHeaders()).willReturn(new HttpHeaders()); ClientHttpConnector firstConnector = mock(ClientHttpConnector.class); given(firstConnector.connect(any(), any(), any())).willReturn(Mono.just(response)); WebClient.Builder firstBuilder = context.getBean(WebClient.Builder.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java index 8c6356a6abc..0f08e5a94e1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java @@ -277,8 +277,12 @@ class WebMvcAutoConfigurationTests { } @Test - void noLocaleResolver() { - this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(LocaleResolver.class)); + void defaultLocaleResolver() { + this.contextRunner.run((context) -> { + assertThat(context).hasSingleBean(LocaleResolver.class); + LocaleResolver localeResolver = context.getBean(LocaleResolver.class); + assertThat(((AcceptHeaderLocaleResolver) localeResolver).getDefaultLocale()).isNull(); + }); } @Test diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 25f9b7db277..7ad1291ba26 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1679,7 +1679,7 @@ bom { ] } } - library("Spring Framework", "5.2.6.RELEASE") { + library("Spring Framework", "5.3.0-SNAPSHOT") { group("org.springframework") { imports = [ "spring-framework-bom" diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java index 4b512bef0c6..8431ca31851 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -28,7 +28,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter; +import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -163,7 +163,7 @@ public class JsonTestersAutoConfiguration { /** * {@link BeanPostProcessor} used to initialize JSON testers. */ - static class JsonMarshalTestersBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter { + static class JsonMarshalTestersBeanPostProcessor implements InstantiationAwareBeanPostProcessor { @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleRepository.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleRepository.java index 643115ea94b..76e28fd542b 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleRepository.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -48,8 +48,7 @@ public class ExampleRepository { } public ExampleEntity findById(int id) { - return this.jdbcTemplate.queryForObject("select id, name from example where id =?", new Object[] { id }, - ROW_MAPPER); + return this.jdbcTemplate.queryForObject("select id, name from example where id =?", ROW_MAPPER, id); } public Collection findAll() { diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestIntegrationTests.java index efe3b4aac65..efa6b14117d 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestIntegrationTests.java @@ -73,7 +73,7 @@ class DataJpaTestIntegrationTests { Long id = this.entities.persistAndGetId(new ExampleEntity("spring", "123"), Long.class); assertThat(id).isNotNull(); String reference = this.jdbcTemplate.queryForObject("SELECT REFERENCE FROM EXAMPLE_ENTITY WHERE ID = ?", - new Object[] { id }, String.class); + String.class, id); assertThat(reference).isEqualTo("123"); } diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java index e153201247c..6b68f0cbdf3 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java @@ -43,8 +43,9 @@ import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder; -import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter; +import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor; import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.beans.factory.support.DefaultBeanNameGenerator; @@ -75,8 +76,8 @@ import org.springframework.util.StringUtils; * @author Andreas Neiser * @since 1.4.0 */ -public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAdapter - implements BeanClassLoaderAware, BeanFactoryAware, BeanFactoryPostProcessor, Ordered { +public class MockitoPostProcessor implements InstantiationAwareBeanPostProcessor, BeanClassLoaderAware, + BeanFactoryAware, BeanFactoryPostProcessor, Ordered { private static final String BEAN_NAME = MockitoPostProcessor.class.getName(); @@ -424,7 +425,7 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda * {@link BeanPostProcessor} to handle {@link SpyBean} definitions. Registered as a * separate processor so that it can be ordered above AOP post processors. */ - static class SpyPostProcessor extends InstantiationAwareBeanPostProcessorAdapter implements PriorityOrdered { + static class SpyPostProcessor implements SmartInstantiationAwareBeanPostProcessor, PriorityOrdered { private static final String BEAN_NAME = SpyPostProcessor.class.getName(); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterIntegrationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterIntegrationTests.java index 0b2999c0df3..0037850a598 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterIntegrationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -48,11 +48,11 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.DispatcherServlet; +import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import static org.assertj.core.api.Assertions.assertThat; @@ -150,7 +150,7 @@ class ErrorPageFilterIntegrationTests { @Override public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new HandlerInterceptorAdapter() { + registry.addInterceptor(new HandlerInterceptor() { @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {