From 33aeb6ee9c6ba2df235ebb09cf9490c92212eee7 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Sun, 11 May 2025 17:01:04 +0200 Subject: [PATCH] Deprecate [Property|Preferences]PlaceholderConfigurer for removal PropertyPlaceholderConfigurer and PreferencesPlaceholderConfigurer have been officially deprecated since Spring Framework 5.2. Since we no longer expect applications to depend on these outdated mechanisms, this commit deprecates these classes "for removal" in Spring Framework 8.0. Closes gh-34880 --- ...eholderConfigurerEnvironmentIntegrationTests.java | 4 ++-- .../config/PreferencesPlaceholderConfigurer.java | 11 ++++++----- .../config/PropertyPlaceholderConfigurer.java | 12 +++++++----- .../config/PropertyPlaceholderConfigurerTests.java | 4 ++-- .../config/PropertyResourceConfigurerTests.java | 4 ++-- .../PropertyPlaceholderBeanDefinitionParser.java | 4 ++-- .../CommonAnnotationBeanPostProcessorTests.java | 8 ++++---- .../ConfigurationClassProcessingTests.java | 2 +- .../ApplicationContextExpressionTests.java | 4 ++-- .../support/BeanFactoryPostProcessorTests.java | 4 ++-- .../PropertyResourceConfigurerIntegrationTests.java | 4 ++-- 11 files changed, 32 insertions(+), 29 deletions(-) diff --git a/integration-tests/src/test/java/org/springframework/core/env/PropertyPlaceholderConfigurerEnvironmentIntegrationTests.java b/integration-tests/src/test/java/org/springframework/core/env/PropertyPlaceholderConfigurerEnvironmentIntegrationTests.java index 248000ce7b..f482ffd50f 100644 --- a/integration-tests/src/test/java/org/springframework/core/env/PropertyPlaceholderConfigurerEnvironmentIntegrationTests.java +++ b/integration-tests/src/test/java/org/springframework/core/env/PropertyPlaceholderConfigurerEnvironmentIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -25,7 +25,7 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.ro class PropertyPlaceholderConfigurerEnvironmentIntegrationTests { @Test - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) void test() { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerBeanDefinition("ppc", diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java index e100e9e314..f4a28b3e14 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -26,8 +26,8 @@ import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.InitializingBean; /** - * Subclass of PropertyPlaceholderConfigurer that supports JDK 1.4's - * Preferences API ({@code java.util.prefs}). + * Subclass of {@link PropertyPlaceholderConfigurer} that supports JDK 1.4's + * {@link Preferences} API. * *

Tries to resolve placeholders as keys first in the user preferences, * then in the system preferences, then in this configurer's properties. @@ -43,9 +43,10 @@ import org.springframework.beans.factory.InitializingBean; * @see #setSystemTreePath * @see #setUserTreePath * @see java.util.prefs.Preferences - * @deprecated as of 5.2, along with {@link PropertyPlaceholderConfigurer} + * @deprecated as of 5.2, along with {@link PropertyPlaceholderConfigurer}; to be removed in 8.0 */ -@Deprecated +@Deprecated(since = "5.2", forRemoval = true) +@SuppressWarnings({"deprecation", "removal"}) public class PreferencesPlaceholderConfigurer extends PropertyPlaceholderConfigurer implements InitializingBean { private @Nullable String systemTreePath; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java index 77d430073e..81d5eb24df 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -52,11 +52,13 @@ import org.springframework.util.StringValueResolver; * @see #setSystemPropertiesModeName * @see PlaceholderConfigurerSupport * @see PropertyOverrideConfigurer - * @deprecated as of 5.2; use {@code org.springframework.context.support.PropertySourcesPlaceholderConfigurer} - * instead which is more flexible through taking advantage of the {@link org.springframework.core.env.Environment} - * and {@link org.springframework.core.env.PropertySource} mechanisms. + * @deprecated as of 5.2, to be removed in 8.0; + * use {@code org.springframework.context.support.PropertySourcesPlaceholderConfigurer} + * instead which is more flexible through taking advantage of the + * {@link org.springframework.core.env.Environment} and + * {@link org.springframework.core.env.PropertySource} mechanisms. */ -@Deprecated +@Deprecated(since = "5.2", forRemoval = true) public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport { /** Never check system properties. */ diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurerTests.java index 01d387a95a..340e7692c9 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -44,7 +44,7 @@ import static org.springframework.beans.factory.support.BeanDefinitionReaderUtil * @author Chris Beams * @author Sam Brannen */ -@SuppressWarnings("deprecation") +@SuppressWarnings({"deprecation", "removal"}) class PropertyPlaceholderConfigurerTests { private static final String P1 = "p1"; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java index 5c764fa87c..23a878332d 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -59,7 +59,7 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @since 02.10.2003 * @see PropertyPlaceholderConfigurerTests */ -@SuppressWarnings("deprecation") +@SuppressWarnings({"deprecation", "removal"}) class PropertyResourceConfigurerTests { static { diff --git a/spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java index 72504ae805..277ee04402 100644 --- a/spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -39,7 +39,7 @@ class PropertyPlaceholderBeanDefinitionParser extends AbstractPropertyLoadingBea @Override - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) protected Class getBeanClass(Element element) { // The default value of system-properties-mode is 'ENVIRONMENT'. This value // indicates that resolution of placeholders against system properties is a diff --git a/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java index 170d26dcf3..bfd003c533 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -227,7 +227,7 @@ class CommonAnnotationBeanPostProcessorTests { bf.registerResolvableDependency(BeanFactory.class, bf); bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory) NestedTestBean::new); - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.setProperty("tb", "testBean4"); @@ -312,7 +312,7 @@ class CommonAnnotationBeanPostProcessorTests { bf.addBeanPostProcessor(bpp); bf.registerResolvableDependency(BeanFactory.class, bf); - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.setProperty("tb", "testBean3"); @@ -363,7 +363,7 @@ class CommonAnnotationBeanPostProcessorTests { bf.addBeanPostProcessor(bpp); bf.registerResolvableDependency(BeanFactory.class, bf); - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.setProperty("tb", "testBean3"); diff --git a/spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java b/spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java index 32d8c012e5..a552e26ede 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java @@ -267,7 +267,7 @@ class ConfigurationClassProcessingTests { void configurationWithPostProcessor() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ConfigWithPostProcessor.class); - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) RootBeanDefinition placeholderConfigurer = new RootBeanDefinition( org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class); placeholderConfigurer.getPropertyValues().add("properties", "myProp=myValue"); diff --git a/spring-context/src/test/java/org/springframework/context/expression/ApplicationContextExpressionTests.java b/spring-context/src/test/java/org/springframework/context/expression/ApplicationContextExpressionTests.java index 4e18f567b6..347aa9171d 100644 --- a/spring-context/src/test/java/org/springframework/context/expression/ApplicationContextExpressionTests.java +++ b/spring-context/src/test/java/org/springframework/context/expression/ApplicationContextExpressionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -68,7 +68,7 @@ import static org.springframework.context.expression.StandardBeanExpressionResol class ApplicationContextExpressionTests { @Test - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) void genericApplicationContext() throws Exception { GenericApplicationContext ac = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(ac); diff --git a/spring-context/src/test/java/org/springframework/context/support/BeanFactoryPostProcessorTests.java b/spring-context/src/test/java/org/springframework/context/support/BeanFactoryPostProcessorTests.java index 7c153e3fd4..b1cb1b8aa3 100644 --- a/spring-context/src/test/java/org/springframework/context/support/BeanFactoryPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/BeanFactoryPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -76,7 +76,7 @@ class BeanFactoryPostProcessorTests { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) void multipleDefinedBeanFactoryPostProcessors() { StaticApplicationContext ac = new StaticApplicationContext(); ac.registerSingleton("tb1", TestBean.class); diff --git a/spring-context/src/test/java/org/springframework/context/support/PropertyResourceConfigurerIntegrationTests.java b/spring-context/src/test/java/org/springframework/context/support/PropertyResourceConfigurerIntegrationTests.java index 5df9f1c089..4efbe86f28 100644 --- a/spring-context/src/test/java/org/springframework/context/support/PropertyResourceConfigurerIntegrationTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/PropertyResourceConfigurerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Sam Brannen * @see org.springframework.beans.factory.config.PropertyResourceConfigurerTests */ -@SuppressWarnings("deprecation") +@SuppressWarnings({"deprecation", "removal"}) class PropertyResourceConfigurerIntegrationTests { @Test