From 07f80348a576303eadda3e923593c89a818c8b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Fri, 24 Jul 2026 15:41:11 +0200 Subject: [PATCH] Polish "Remove APIs that were deprecated for removal in 4.2" See gh-50955 --- .../OperationMethodParameterTests.java | 17 +- .../BatchJdbcAutoConfiguration.java | 15 +- .../BatchJdbcAutoConfigurationTests.java | 28 -- .../autoconfigure/BatchAutoConfiguration.java | 15 +- .../BatchAutoConfigurationTests.java | 25 -- ...ClientHttpMessageConvertersCustomizer.java | 32 +-- ...ServerHttpMessageConvertersCustomizer.java | 33 +-- .../autoconfigure/HttpMessageConverters.java | 262 ------------------ ...ttpMessageConvertersAutoConfiguration.java | 10 +- .../HttpMessageConvertersTests.java | 192 ------------- .../WebServerGracefulShutdownLifecycle.java | 9 - 11 files changed, 26 insertions(+), 612 deletions(-) delete mode 100644 module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConverters.java delete mode 100644 module/spring-boot-http-converter/src/test/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersTests.java diff --git a/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameterTests.java b/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameterTests.java index f608b4b4bff..fe4c898aa4f 100644 --- a/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameterTests.java +++ b/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameterTests.java @@ -18,6 +18,7 @@ package org.springframework.boot.actuate.endpoint.invoke.reflect; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.boot.actuate.endpoint.annotation.Selector; @@ -36,8 +37,6 @@ class OperationMethodParameterTests { private final Method example = findMethod("example", String.class, String.class); - private final Method exampleSpringNullable = findMethod("exampleSpringNullable", String.class, String.class); - private final Method exampleAnnotation = findMethod("exampleAnnotation", String.class); @Test @@ -64,14 +63,6 @@ class OperationMethodParameterTests { assertThat(parameter.isMandatory()).isFalse(); } - @Test - @Deprecated(since = "4.0.0") - void isMandatoryWhenSpringNullableAnnotationShouldReturnFalse() { - OperationMethodParameter parameter = new OperationMethodParameter("name", - this.exampleSpringNullable.getParameters()[1]); - assertThat(parameter.isMandatory()).isFalse(); - } - @Test void getAnnotationShouldReturnAnnotation() { OperationMethodParameter parameter = new OperationMethodParameter("name", @@ -87,11 +78,7 @@ class OperationMethodParameterTests { return method; } - void example(String one, @org.jspecify.annotations.Nullable String two) { - } - - @Deprecated(since = "4.0.0") - void exampleSpringNullable(String one, @org.springframework.lang.Nullable String two) { + void example(String one, @Nullable String two) { } void exampleAnnotation(@Selector(match = Match.ALL_REMAINING) String allRemaining) { diff --git a/module/spring-boot-batch-jdbc/src/main/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfiguration.java b/module/spring-boot-batch-jdbc/src/main/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfiguration.java index 65d914eea4e..db76ac252fb 100644 --- a/module/spring-boot-batch-jdbc/src/main/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfiguration.java +++ b/module/spring-boot-batch-jdbc/src/main/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfiguration.java @@ -25,7 +25,6 @@ import org.jspecify.annotations.Nullable; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; import org.springframework.batch.core.configuration.support.JdbcDefaultBatchConfiguration; -import org.springframework.batch.core.converter.JobParametersConverter; import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.core.repository.ExecutionContextSerializer; import org.springframework.beans.factory.ObjectProvider; @@ -91,23 +90,19 @@ public final class BatchJdbcAutoConfiguration { private final @Nullable ExecutionContextSerializer executionContextSerializer; - private final @Nullable JobParametersConverter jobParametersConverter; - SpringBootBatchJdbcConfiguration(DataSource dataSource, @BatchDataSource ObjectProvider batchDataSource, PlatformTransactionManager transactionManager, @BatchTransactionManager ObjectProvider batchTransactionManager, @BatchTaskExecutor ObjectProvider batchTaskExecutor, BatchJdbcProperties properties, ObjectProvider batchConversionServiceCustomizers, - ObjectProvider executionContextSerializer, - ObjectProvider jobParametersConverter) { + ObjectProvider executionContextSerializer) { this.dataSource = batchDataSource.getIfAvailable(() -> dataSource); this.transactionManager = batchTransactionManager.getIfAvailable(() -> transactionManager); this.taskExecutor = batchTaskExecutor.getIfAvailable(); this.properties = properties; this.batchConversionServiceCustomizers = batchConversionServiceCustomizers.orderedStream().toList(); this.executionContextSerializer = executionContextSerializer.getIfAvailable(); - this.jobParametersConverter = jobParametersConverter.getIfAvailable(); } @Override @@ -152,14 +147,6 @@ public final class BatchJdbcAutoConfiguration { : super.getExecutionContextSerializer(); } - @Override - @Deprecated(since = "4.0.0", forRemoval = true) - @SuppressWarnings("removal") - protected JobParametersConverter getJobParametersConverter() { - return (this.jobParametersConverter != null) ? this.jobParametersConverter - : super.getJobParametersConverter(); - } - @Override protected TaskExecutor getTaskExecutor() { return (this.taskExecutor != null) ? this.taskExecutor : super.getTaskExecutor(); diff --git a/module/spring-boot-batch-jdbc/src/test/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfigurationTests.java b/module/spring-boot-batch-jdbc/src/test/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfigurationTests.java index 479006a12ed..bc61ad71644 100644 --- a/module/spring-boot-batch-jdbc/src/test/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfigurationTests.java +++ b/module/spring-boot-batch-jdbc/src/test/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchJdbcAutoConfigurationTests.java @@ -31,9 +31,6 @@ import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; -import org.springframework.batch.core.converter.DefaultJobParametersConverter; -import org.springframework.batch.core.converter.JobParametersConverter; -import org.springframework.batch.core.converter.JsonJobParametersConverter; import org.springframework.batch.core.job.AbstractJob; import org.springframework.batch.core.job.Job; import org.springframework.batch.core.job.JobExecution; @@ -514,31 +511,6 @@ class BatchJdbcAutoConfigurationTests { } - @Test - @Deprecated(since = "4.0.0", forRemoval = true) - @SuppressWarnings("removal") - void customJobParametersConverterIsUsed() { - this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) - .withBean(JobParametersConverter.class, JsonJobParametersConverter::new) - .withPropertyValues("spring.datasource.generate-unique-name=true") - .run((context) -> { - assertThat(context).hasSingleBean(JsonJobParametersConverter.class); - assertThat(context.getBean(SpringBootBatchJdbcConfiguration.class).getJobParametersConverter()) - .isInstanceOf(JsonJobParametersConverter.class); - }); - } - - @Test - @Deprecated(since = "4.0.0", forRemoval = true) - @SuppressWarnings("removal") - void defaultJobParametersConverterIsUsed() { - this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class).run((context) -> { - assertThat(context).doesNotHaveBean(JobParametersConverter.class); - assertThat(context.getBean(SpringBootBatchJdbcConfiguration.class).getJobParametersConverter()) - .isInstanceOf(DefaultJobParametersConverter.class); - }); - } - private JobLauncherApplicationRunner createInstance(String... registeredJobNames) { JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner(mock(JobOperator.class)); JobRegistry jobRegistry = mock(JobRegistry.class); diff --git a/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/BatchAutoConfiguration.java b/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/BatchAutoConfiguration.java index bf2dc30490c..dcb3a75054c 100644 --- a/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/BatchAutoConfiguration.java +++ b/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/BatchAutoConfiguration.java @@ -20,7 +20,6 @@ import org.jspecify.annotations.Nullable; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; -import org.springframework.batch.core.converter.JobParametersConverter; import org.springframework.batch.core.launch.JobOperator; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -49,20 +48,8 @@ public final class BatchAutoConfiguration { private final @Nullable TaskExecutor taskExecutor; - private final @Nullable JobParametersConverter jobParametersConverter; - - SpringBootBatchDefaultConfiguration(@BatchTaskExecutor ObjectProvider batchTaskExecutor, - ObjectProvider jobParametersConverter) { + SpringBootBatchDefaultConfiguration(@BatchTaskExecutor ObjectProvider batchTaskExecutor) { this.taskExecutor = batchTaskExecutor.getIfAvailable(); - this.jobParametersConverter = jobParametersConverter.getIfAvailable(); - } - - @Override - @Deprecated(since = "4.0.0", forRemoval = true) - @SuppressWarnings("removal") - protected JobParametersConverter getJobParametersConverter() { - return (this.jobParametersConverter != null) ? this.jobParametersConverter - : super.getJobParametersConverter(); } @Override diff --git a/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/BatchAutoConfigurationTests.java b/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/BatchAutoConfigurationTests.java index ce5264579a6..7537b733fe5 100644 --- a/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/BatchAutoConfigurationTests.java +++ b/module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/BatchAutoConfigurationTests.java @@ -25,9 +25,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; -import org.springframework.batch.core.converter.DefaultJobParametersConverter; -import org.springframework.batch.core.converter.JobParametersConverter; -import org.springframework.batch.core.converter.JsonJobParametersConverter; import org.springframework.batch.core.job.Job; import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.core.repository.JobRepository; @@ -135,28 +132,6 @@ class BatchAutoConfigurationTests { .withMessage("No job found with name 'three'"); } - @Test - @Deprecated(since = "4.0.0", forRemoval = true) - @SuppressWarnings("removal") - void customJobParametersConverterIsUsed() { - this.contextRunner.withBean(JobParametersConverter.class, JsonJobParametersConverter::new).run((context) -> { - assertThat(context).hasSingleBean(JsonJobParametersConverter.class); - assertThat(context.getBean(SpringBootBatchDefaultConfiguration.class).getJobParametersConverter()) - .isInstanceOf(JsonJobParametersConverter.class); - }); - } - - @Test - @Deprecated(since = "4.0.0", forRemoval = true) - @SuppressWarnings("removal") - void defaultJobParametersConverterIsUsed() { - this.contextRunner.run((context) -> { - assertThat(context).doesNotHaveBean(JobParametersConverter.class); - assertThat(context.getBean(SpringBootBatchDefaultConfiguration.class).getJobParametersConverter()) - .isInstanceOf(DefaultJobParametersConverter.class); - }); - } - private JobLauncherApplicationRunner createInstance(String... registeredJobNames) { JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner(mock(JobOperator.class)); JobRegistry jobRegistry = mock(JobRegistry.class); diff --git a/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultClientHttpMessageConvertersCustomizer.java b/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultClientHttpMessageConvertersCustomizer.java index 995863e5d1a..ddd5e838e6b 100644 --- a/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultClientHttpMessageConvertersCustomizer.java +++ b/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultClientHttpMessageConvertersCustomizer.java @@ -18,41 +18,29 @@ package org.springframework.boot.http.converter.autoconfigure; import java.util.Collection; -import org.jspecify.annotations.Nullable; - import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverters.ClientBuilder; import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter; -@SuppressWarnings("deprecation") class DefaultClientHttpMessageConvertersCustomizer implements ClientHttpMessageConvertersCustomizer { - private final @Nullable HttpMessageConverters legacyConverters; - private final Collection> converters; - DefaultClientHttpMessageConvertersCustomizer(@Nullable HttpMessageConverters legacyConverters, - Collection> converters) { - this.legacyConverters = legacyConverters; + DefaultClientHttpMessageConvertersCustomizer(Collection> converters) { this.converters = converters; } @Override public void customize(ClientBuilder builder) { - if (this.legacyConverters != null) { - this.legacyConverters.forEach(builder::addCustomConverter); - } - else { - builder.registerDefaults(); - this.converters.forEach((converter) -> { - if (converter instanceof KotlinSerializationJsonHttpMessageConverter) { - builder.withKotlinSerializationJsonConverter(converter); - } - else { - builder.addCustomConverter(converter); - } - }); - } + builder.registerDefaults(); + this.converters.forEach((converter) -> { + if (converter instanceof KotlinSerializationJsonHttpMessageConverter) { + builder.withKotlinSerializationJsonConverter(converter); + } + else { + builder.addCustomConverter(converter); + } + }); } } diff --git a/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultServerHttpMessageConvertersCustomizer.java b/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultServerHttpMessageConvertersCustomizer.java index cab0bcd6640..004e9759d88 100644 --- a/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultServerHttpMessageConvertersCustomizer.java +++ b/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultServerHttpMessageConvertersCustomizer.java @@ -18,42 +18,29 @@ package org.springframework.boot.http.converter.autoconfigure; import java.util.Collection; -import org.jspecify.annotations.Nullable; - import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverters.ServerBuilder; import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter; -@SuppressWarnings("deprecation") class DefaultServerHttpMessageConvertersCustomizer implements ServerHttpMessageConvertersCustomizer { - private final @Nullable HttpMessageConverters legacyConverters; - private final Collection> converters; - DefaultServerHttpMessageConvertersCustomizer(@Nullable HttpMessageConverters legacyConverters, - Collection> converters) { - - this.legacyConverters = legacyConverters; + DefaultServerHttpMessageConvertersCustomizer(Collection> converters) { this.converters = converters; } @Override public void customize(ServerBuilder builder) { - if (this.legacyConverters != null) { - this.legacyConverters.forEach(builder::addCustomConverter); - } - else { - builder.registerDefaults(); - this.converters.forEach((converter) -> { - if (converter instanceof KotlinSerializationJsonHttpMessageConverter) { - builder.withKotlinSerializationJsonConverter(converter); - } - else { - builder.addCustomConverter(converter); - } - }); - } + builder.registerDefaults(); + this.converters.forEach((converter) -> { + if (converter instanceof KotlinSerializationJsonHttpMessageConverter) { + builder.withKotlinSerializationJsonConverter(converter); + } + else { + builder.addCustomConverter(converter); + } + }); } } diff --git a/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConverters.java b/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConverters.java deleted file mode 100644 index 7a9bbd2f329..00000000000 --- a/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConverters.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright 2012-present 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 - * - * https://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.boot.http.converter.autoconfigure; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; -import org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter; -import org.springframework.util.ClassUtils; -import org.springframework.util.CollectionUtils; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; - -/** - * Bean used to manage the {@link HttpMessageConverter}s used in a Spring Boot - * application. Provides a convenient way to add and merge additional - * {@link HttpMessageConverter}s to a web application. - *

- * An instance of this bean can be registered with specific - * {@link #HttpMessageConverters(HttpMessageConverter...) additional converters} if - * needed, otherwise default converters will be used. - *

- * NOTE: The default converters used are the same as standard Spring MVC (see - * {@link WebMvcConfigurationSupport}) with some slight re-ordering to put XML converters - * at the back of the list. - * - * @author Dave Syer - * @author Phillip Webb - * @author Andy Wilkinson - * @since 4.0.0 - * @see #HttpMessageConverters(HttpMessageConverter...) - * @see #HttpMessageConverters(Collection) - * @see #getConverters() - * @deprecated since 4.0.0 for removal in 4.2.0 in favor of - * {@link ClientHttpMessageConvertersCustomizer} and - * {@link ServerHttpMessageConvertersCustomizer}. - */ -@Deprecated(since = "4.0.0") -public class HttpMessageConverters implements Iterable> { - - private static final List> NON_REPLACING_CONVERTERS; - - static { - List> nonReplacingConverters = new ArrayList<>(); - addClassIfExists(nonReplacingConverters, - "org.springframework.hateoas.server.mvc.TypeConstrainedJacksonJsonHttpMessageConverter"); - NON_REPLACING_CONVERTERS = Collections.unmodifiableList(nonReplacingConverters); - } - - private static final MultiValueMap, Class> EQUIVALENT_CONVERTERS; - - static { - MultiValueMap, Class> equivalentConverters = new LinkedMultiValueMap<>(); - putIfExists(equivalentConverters, "org.springframework.http.converter.json.JacksonJsonHttpMessageConverter", - "org.springframework.http.converter.json.MappingJackson2HttpMessageConverter", - "org.springframework.http.converter.json.GsonHttpMessageConverter", - "org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter"); - putIfExists(equivalentConverters, "org.springframework.http.converter.json.MappingJackson2HttpMessageConverter", - "org.springframework.http.converter.json.GsonHttpMessageConverter", - "org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter"); - EQUIVALENT_CONVERTERS = CollectionUtils.unmodifiableMultiValueMap(equivalentConverters); - } - - private final List> converters; - - /** - * Create a new {@link HttpMessageConverters} instance with the specified additional - * converters. - * @param additionalConverters additional converters to be added. Items are added just - * before any default converter of the same type (or at the front of the list if no - * default converter is found). The {@link #postProcessConverters(List)} method can be - * used for further converter manipulation. - */ - public HttpMessageConverters(HttpMessageConverter... additionalConverters) { - this(Arrays.asList(additionalConverters)); - } - - /** - * Create a new {@link HttpMessageConverters} instance with the specified additional - * converters. - * @param additionalConverters additional converters to be added. Items are added just - * before any default converter of the same type (or at the front of the list if no - * default converter is found). The {@link #postProcessConverters(List)} method can be - * used for further converter manipulation. - */ - public HttpMessageConverters(Collection> additionalConverters) { - this(true, additionalConverters); - } - - /** - * Create a new {@link HttpMessageConverters} instance with the specified converters. - * @param addDefaultConverters if default converters should be added - * @param converters converters to be added. Items are added just before any default - * converter of the same type (or at the front of the list if no default converter is - * found). The {@link #postProcessConverters(List)} method can be used for further - * converter manipulation. - */ - public HttpMessageConverters(boolean addDefaultConverters, Collection> converters) { - List> combined = getCombinedConverters(converters, - addDefaultConverters ? getDefaultConverters() : Collections.emptyList()); - combined = postProcessConverters(combined); - this.converters = Collections.unmodifiableList(combined); - } - - private List> getCombinedConverters(Collection> converters, - List> defaultConverters) { - List> combined = new ArrayList<>(); - List> processing = new ArrayList<>(converters); - for (HttpMessageConverter defaultConverter : defaultConverters) { - Iterator> iterator = processing.iterator(); - while (iterator.hasNext()) { - HttpMessageConverter candidate = iterator.next(); - if (isReplacement(defaultConverter, candidate)) { - combined.add(candidate); - iterator.remove(); - } - } - combined.add(defaultConverter); - if (defaultConverter instanceof AllEncompassingFormHttpMessageConverter allEncompassingConverter) { - configurePartConverters(allEncompassingConverter, converters); - } - } - combined.addAll(0, processing); - return combined; - } - - private boolean isReplacement(HttpMessageConverter defaultConverter, HttpMessageConverter candidate) { - for (Class nonReplacingConverter : NON_REPLACING_CONVERTERS) { - if (nonReplacingConverter.isInstance(candidate)) { - return false; - } - } - Class converterClass = defaultConverter.getClass(); - if (ClassUtils.isAssignableValue(converterClass, candidate)) { - return true; - } - List> equivalentClasses = EQUIVALENT_CONVERTERS.get(converterClass); - return (equivalentClasses != null) && equivalentClasses.stream() - .anyMatch((equivalentClass) -> equivalentClass != null - && ClassUtils.isAssignableValue(equivalentClass, candidate)); - } - - private void configurePartConverters(AllEncompassingFormHttpMessageConverter formConverter, - Collection> converters) { - List> partConverters = formConverter.getPartConverters(); - List> combinedConverters = getCombinedConverters(converters, partConverters); - combinedConverters = postProcessPartConverters(combinedConverters); - formConverter.setPartConverters(combinedConverters); - } - - /** - * Method that can be used to post-process the {@link HttpMessageConverter} list - * before it is used. - * @param converters a mutable list of the converters that will be used. - * @return the final converts list to use - */ - protected List> postProcessConverters(List> converters) { - return converters; - } - - /** - * Method that can be used to post-process the {@link HttpMessageConverter} list - * before it is used to configure the part converters of - * {@link AllEncompassingFormHttpMessageConverter}. - * @param converters a mutable list of the converters that will be used. - * @return the final converts list to use - */ - protected List> postProcessPartConverters(List> converters) { - return converters; - } - - private List> getDefaultConverters() { - List> converters = new ArrayList<>(); - if (ClassUtils.isPresent("org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport", - null)) { - converters.addAll(new WebMvcConfigurationSupport() { - - public List> defaultMessageConverters() { - return super.getMessageConverters(); - } - - }.defaultMessageConverters()); - } - else { - converters.addAll(new RestTemplate().getMessageConverters()); - } - reorderXmlConvertersToEnd(converters); - return converters; - } - - @SuppressWarnings("removal") - private void reorderXmlConvertersToEnd(List> converters) { - List> xml = new ArrayList<>(); - for (Iterator> iterator = converters.iterator(); iterator.hasNext();) { - HttpMessageConverter converter = iterator.next(); - if ((converter instanceof AbstractXmlHttpMessageConverter) - || (converter instanceof org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)) { - xml.add(converter); - iterator.remove(); - } - } - converters.addAll(xml); - } - - @Override - public Iterator> iterator() { - return getConverters().iterator(); - } - - /** - * Return an immutable list of the converters in the order that they will be - * registered. - * @return the converters - */ - public List> getConverters() { - return this.converters; - } - - private static void addClassIfExists(List> list, String className) { - try { - list.add(Class.forName(className)); - } - catch (ClassNotFoundException | NoClassDefFoundError ex) { - // Ignore - } - } - - private static void putIfExists(MultiValueMap, Class> map, String keyClassName, - String... valueClassNames) { - for (String valueClassName : valueClassNames) { - try { - map.add(Class.forName(keyClassName), Class.forName(valueClassName)); - } - catch (ClassNotFoundException | NoClassDefFoundError ex) { - // Ignore - } - } - } - -} diff --git a/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersAutoConfiguration.java b/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersAutoConfiguration.java index 6b58a03eec7..b91ac7c9457 100644 --- a/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersAutoConfiguration.java +++ b/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersAutoConfiguration.java @@ -69,22 +69,16 @@ public final class HttpMessageConvertersAutoConfiguration { @Bean @Order(0) - @SuppressWarnings("deprecation") ClientHttpMessageConvertersCustomizer clientConvertersCustomizer( - ObjectProvider legacyConverters, ObjectProvider> converters) { - return new DefaultClientHttpMessageConvertersCustomizer(legacyConverters.getIfAvailable(), - converters.orderedStream().toList()); + return new DefaultClientHttpMessageConvertersCustomizer(converters.orderedStream().toList()); } @Bean @Order(0) - @SuppressWarnings("deprecation") ServerHttpMessageConvertersCustomizer serverConvertersCustomizer( - ObjectProvider legacyConverters, ObjectProvider> converters) { - return new DefaultServerHttpMessageConvertersCustomizer(legacyConverters.getIfAvailable(), - converters.orderedStream().toList()); + return new DefaultServerHttpMessageConvertersCustomizer(converters.orderedStream().toList()); } @Configuration(proxyBeanMethods = false) diff --git a/module/spring-boot-http-converter/src/test/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersTests.java b/module/spring-boot-http-converter/src/test/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersTests.java deleted file mode 100644 index 82b7d679552..00000000000 --- a/module/spring-boot-http-converter/src/test/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersTests.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2012-present 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 - * - * https://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.boot.http.converter.autoconfigure; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Stream; - -import org.jspecify.annotations.Nullable; -import org.junit.jupiter.api.Test; - -import org.springframework.http.converter.ByteArrayHttpMessageConverter; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.ResourceHttpMessageConverter; -import org.springframework.http.converter.ResourceRegionHttpMessageConverter; -import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.http.converter.cbor.JacksonCborHttpMessageConverter; -import org.springframework.http.converter.json.GsonHttpMessageConverter; -import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; -import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter; -import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; -import org.springframework.http.converter.xml.JacksonXmlHttpMessageConverter; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link HttpMessageConverters}. - * - * @author Dave Syer - * @author Phillip Webb - */ -@SuppressWarnings("deprecation") -class HttpMessageConvertersTests { - - @Test - void containsDefaults() { - HttpMessageConverters converters = new HttpMessageConverters(); - List> converterClasses = new ArrayList<>(); - for (HttpMessageConverter converter : converters) { - converterClasses.add(converter.getClass()); - } - assertThat(converterClasses).containsExactly(ByteArrayHttpMessageConverter.class, - StringHttpMessageConverter.class, ResourceHttpMessageConverter.class, - ResourceRegionHttpMessageConverter.class, AllEncompassingFormHttpMessageConverter.class, - KotlinSerializationJsonHttpMessageConverter.class, JacksonJsonHttpMessageConverter.class, - JacksonCborHttpMessageConverter.class, JacksonXmlHttpMessageConverter.class); - } - - @Test - void addBeforeExistingConverter() { - JacksonJsonHttpMessageConverter converter1 = new JacksonJsonHttpMessageConverter(); - JacksonJsonHttpMessageConverter converter2 = new JacksonJsonHttpMessageConverter(); - HttpMessageConverters converters = new HttpMessageConverters(converter1, converter2); - assertThat(converters.getConverters()).contains(converter1); - assertThat(converters.getConverters()).contains(converter2); - List httpConverters = new ArrayList<>(); - for (HttpMessageConverter candidate : converters) { - if (candidate instanceof JacksonJsonHttpMessageConverter jsonConverter) { - httpConverters.add(jsonConverter); - } - } - // The existing converter is still there, but with a lower priority - assertThat(httpConverters).hasSize(3); - assertThat(httpConverters.indexOf(converter1)).isZero(); - assertThat(httpConverters.indexOf(converter2)).isOne(); - assertThat(converters.getConverters().indexOf(converter1)).isNotZero(); - } - - @Test - void addBeforeExistingEquivalentConverter() { - GsonHttpMessageConverter converter1 = new GsonHttpMessageConverter(); - HttpMessageConverters converters = new HttpMessageConverters(converter1); - Stream> converterClasses = converters.getConverters().stream().map(HttpMessageConverter::getClass); - assertThat(converterClasses).containsSequence(KotlinSerializationJsonHttpMessageConverter.class, - GsonHttpMessageConverter.class, JacksonJsonHttpMessageConverter.class); - } - - @Test - void addBeforeExistingAnotherEquivalentConverter() { - KotlinSerializationJsonHttpMessageConverter converter1 = new KotlinSerializationJsonHttpMessageConverter(); - HttpMessageConverters converters = new HttpMessageConverters(converter1); - Stream> converterClasses = converters.getConverters().stream().map(HttpMessageConverter::getClass); - assertThat(converterClasses).containsSequence(KotlinSerializationJsonHttpMessageConverter.class, - JacksonJsonHttpMessageConverter.class); - } - - @Test - void addBeforeExistingMultipleEquivalentConverters() { - GsonHttpMessageConverter converter1 = new GsonHttpMessageConverter(); - KotlinSerializationJsonHttpMessageConverter converter2 = new KotlinSerializationJsonHttpMessageConverter(); - HttpMessageConverters converters = new HttpMessageConverters(converter1, converter2); - Stream> converterClasses = converters.getConverters().stream().map(HttpMessageConverter::getClass); - assertThat(converterClasses).containsSequence(KotlinSerializationJsonHttpMessageConverter.class, - GsonHttpMessageConverter.class, JacksonJsonHttpMessageConverter.class); - } - - @Test - void addNewConverters() { - HttpMessageConverter converter1 = mock(HttpMessageConverter.class); - HttpMessageConverter converter2 = mock(HttpMessageConverter.class); - HttpMessageConverters converters = new HttpMessageConverters(converter1, converter2); - assertThat(converters.getConverters().get(0)).isEqualTo(converter1); - assertThat(converters.getConverters().get(1)).isEqualTo(converter2); - } - - @Test - void convertersAreAddedToFormPartConverter() { - HttpMessageConverter converter1 = mock(HttpMessageConverter.class); - HttpMessageConverter converter2 = mock(HttpMessageConverter.class); - List> converters = new HttpMessageConverters(converter1, converter2).getConverters(); - List> partConverters = extractFormPartConverters(converters); - assertThat(partConverters.get(0)).isEqualTo(converter1); - assertThat(partConverters.get(1)).isEqualTo(converter2); - } - - @Test - void postProcessConverters() { - HttpMessageConverters converters = new HttpMessageConverters() { - - @Override - protected List> postProcessConverters(List> converters) { - converters.removeIf(JacksonXmlHttpMessageConverter.class::isInstance); - return converters; - } - - }; - List> converterClasses = new ArrayList<>(); - for (HttpMessageConverter converter : converters) { - converterClasses.add(converter.getClass()); - } - assertThat(converterClasses).containsExactly(ByteArrayHttpMessageConverter.class, - StringHttpMessageConverter.class, ResourceHttpMessageConverter.class, - ResourceRegionHttpMessageConverter.class, AllEncompassingFormHttpMessageConverter.class, - KotlinSerializationJsonHttpMessageConverter.class, JacksonJsonHttpMessageConverter.class, - JacksonCborHttpMessageConverter.class); - } - - @Test - void postProcessPartConverters() { - HttpMessageConverters converters = new HttpMessageConverters() { - - @Override - protected List> postProcessPartConverters( - List> converters) { - converters.removeIf(JacksonXmlHttpMessageConverter.class::isInstance); - return converters; - } - - }; - List> converterClasses = new ArrayList<>(); - for (HttpMessageConverter converter : extractFormPartConverters(converters.getConverters())) { - converterClasses.add(converter.getClass()); - } - assertThat(converterClasses).containsExactly(ByteArrayHttpMessageConverter.class, - StringHttpMessageConverter.class, ResourceHttpMessageConverter.class, - KotlinSerializationJsonHttpMessageConverter.class, JacksonJsonHttpMessageConverter.class, - JacksonCborHttpMessageConverter.class); - } - - private List> extractFormPartConverters(List> converters) { - AllEncompassingFormHttpMessageConverter formConverter = findFormConverter(converters); - assertThat(formConverter).isNotNull(); - return formConverter.getPartConverters(); - } - - private @Nullable AllEncompassingFormHttpMessageConverter findFormConverter( - Collection> converters) { - for (HttpMessageConverter converter : converters) { - if (converter instanceof AllEncompassingFormHttpMessageConverter allEncompassingConverter) { - return allEncompassingConverter; - } - } - return null; - } - -} diff --git a/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/context/WebServerGracefulShutdownLifecycle.java b/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/context/WebServerGracefulShutdownLifecycle.java index 5b7fe4ccc3c..23361024a41 100644 --- a/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/context/WebServerGracefulShutdownLifecycle.java +++ b/module/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/context/WebServerGracefulShutdownLifecycle.java @@ -27,15 +27,6 @@ import org.springframework.context.SmartLifecycle; */ public final class WebServerGracefulShutdownLifecycle implements SmartLifecycle { - /** - * {@link SmartLifecycle#getPhase() SmartLifecycle phase} in which graceful shutdown - * of the web server is performed. - * @deprecated as of 4.0.0 in favor of - * {@link WebServerApplicationContext#GRACEFUL_SHUTDOWN_PHASE} - */ - @Deprecated(since = "4.0.0", forRemoval = true) - public static final int SMART_LIFECYCLE_PHASE = SmartLifecycle.DEFAULT_PHASE - 1024; - private final WebServer webServer; private volatile boolean running;