Skip to content

Commit c75b06c

Browse files
committed
Remove @ImmutableConfigurationProperties
Closes gh-18563
1 parent 1a7a311 commit c75b06c

File tree

12 files changed

+36
-98
lines changed

12 files changed

+36
-98
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,12 @@ The example in the previous section can be rewritten in an immutable fashion as
849849
import java.net.InetAddress;
850850
import java.util.List;
851851
852-
import org.springframework.boot.context.properties.ImmutableConfigurationProperties;
852+
import org.springframework.boot.context.properties.ConfigurationProperties;
853+
import org.springframework.boot.context.properties.ConstructorBinding;
853854
import org.springframework.boot.context.properties.DefaultValue;
854855
855-
@ImmutableConfigurationProperties("acme")
856+
@ConstructorBinding
857+
@ConfigurationProperties("acme")
856858
public class AcmeProperties {
857859
858860
private final boolean enabled;
@@ -899,18 +901,17 @@ The example in the previous section can be rewritten in an immutable fashion as
899901
}
900902
----
901903

902-
In this setup, the `@ImmutableConfigurationProperties` annotation is used to indicate that constructor binding should be used.
904+
In this setup, the `@ConstructorBinding` annotation is used to indicate that constructor binding should be used.
903905
This means that the binder will expect to find a constructor with the parameters that you wish to have bound.
904906

905-
Nested members of a `@ImmutableConfigurationProperties` class (such as `Security` in the example above) will also be bound via their constructor.
907+
Nested members of a `@ConstructorBinding` class (such as `Security` in the example above) will also be bound via their constructor.
906908

907909
Default values can be specified using `@DefaultValue` and the same conversion service will be applied to coerce the `String` value to the target type of a missing property.
908910

909911
NOTE: To use constructor binding the class must be enabled using `@EnableConfigurationProperties` or configuration property scanning.
910912
You cannot use constructor binding with beans that are created by the regular Spring mechanisms (e.g. `@Component` beans, beans created via `@Bean` methods or beans loaded using `@Import`)
911913

912-
TIP: `@ImmutableConfigurationProperties` is actually a meta-annotation composed of `@ConfigurationProperties` and `@ConstructorBinding`.
913-
If you have more than one constructor for your class you can also use `@ConstructorBinding` directly on actual constructor that should be bound.
914+
TIP: If you have more than one constructor for your class you can also use `@ConstructorBinding` directly on the constructor that should be bound.
914915

915916

916917

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/ExampleProperties.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@
1616

1717
package org.springframework.boot.test.autoconfigure.web.client;
1818

19-
import org.springframework.boot.context.properties.ImmutableConfigurationProperties;
19+
import org.springframework.boot.context.properties.ConfigurationProperties;
20+
import org.springframework.boot.context.properties.ConstructorBinding;
2021
import org.springframework.boot.context.properties.bind.DefaultValue;
2122

2223
/**
23-
* Example {@link ImmutableConfigurationProperties @ImmutableConfigurationProperties} used
24-
* to test the use of configuration properties scan with sliced test.
24+
* Example {@link ConstructorBinding constructor-bound}
25+
* {@link ConfigurationProperties @ConfigurationProperties} used to test the use of
26+
* configuration properties scan with sliced test.
2527
*
2628
* @author Stephane Nicoll
2729
*/
28-
@ImmutableConfigurationProperties("example")
30+
@ConstructorBinding
31+
@ConfigurationProperties("example")
2932
public class ExampleProperties {
3033

3134
private final String name;

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
* @since 1.0.0
4141
* @see ConfigurationPropertiesScan
4242
* @see ConstructorBinding
43-
* @see ImmutableConfigurationProperties
4443
* @see ConfigurationPropertiesBindingPostProcessor
4544
* @see EnableConfigurationProperties
4645
*/

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConstructorBinding.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
* @author Phillip Webb
3131
* @since 2.2.0
3232
* @see ConfigurationProperties
33-
* @see ImmutableConfigurationProperties
3433
*/
3534
@Target({ ElementType.TYPE, ElementType.CONSTRUCTOR })
3635
@Retention(RetentionPolicy.RUNTIME)

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ImmutableConfigurationProperties.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanRegistrarTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ static class NoAnnotationConfigurationProperties {
9090

9191
}
9292

93-
@ImmutableConfigurationProperties("valuecp")
93+
@ConstructorBinding
94+
@ConfigurationProperties("valuecp")
9495
static class ValueObjectConfigurationProperties {
9596

9697
ValueObjectConfigurationProperties(String name) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanTests.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,6 @@ void bindTypeForClassWhenNoConstructorBindingOnTypeReturnsValueObject() {
202202
assertThat(bindType).isEqualTo(BindMethod.VALUE_OBJECT);
203203
}
204204

205-
@Test
206-
void bindTypeForClassWhenNoMetaConstructorBindingOnTypeReturnsValueObject() {
207-
BindMethod bindType = BindMethod.forClass(MetaConstructorBindingOnType.class);
208-
assertThat(bindType).isEqualTo(BindMethod.VALUE_OBJECT);
209-
}
210-
211205
@Test
212206
void bindTypeForClassWhenNoConstructorBindingOnConstructorReturnsValueObject() {
213207
BindMethod bindType = BindMethod.forClass(ConstructorBindingOnConstructor.class);
@@ -383,14 +377,6 @@ static class ConstructorBindingOnType {
383377

384378
}
385379

386-
@ImmutableConfigurationProperties
387-
static class MetaConstructorBindingOnType {
388-
389-
MetaConstructorBindingOnType(String name) {
390-
}
391-
392-
}
393-
394380
@ConfigurationProperties
395381
static class ConstructorBindingOnConstructor {
396382

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,8 @@ void setAnotherSize(DataSize anotherSize) {
18061806

18071807
}
18081808

1809-
@ImmutableConfigurationProperties(prefix = "test")
1809+
@ConstructorBinding
1810+
@ConfigurationProperties(prefix = "test")
18101811
static class OtherInjectedProperties {
18111812

18121813
final DataSizeProperties dataSizeProperties;
@@ -1823,7 +1824,8 @@ static class OtherInjectPropertiesConfiguration {
18231824

18241825
}
18251826

1826-
@ImmutableConfigurationProperties(prefix = "test")
1827+
@ConstructorBinding
1828+
@ConfigurationProperties(prefix = "test")
18271829
@Validated
18281830
static class ConstructorParameterProperties {
18291831

@@ -1854,7 +1856,8 @@ static class ImportConstructorParameterPropertiesConfiguration {
18541856

18551857
}
18561858

1857-
@ImmutableConfigurationProperties(prefix = "test")
1859+
@ConstructorBinding
1860+
@ConfigurationProperties(prefix = "test")
18581861
@Validated
18591862
static class ConstructorParameterValidatedProperties {
18601863

@@ -1973,7 +1976,8 @@ static class NestedConstructorPropertiesConfiguration {
19731976

19741977
}
19751978

1976-
@ImmutableConfigurationProperties("test")
1979+
@ConstructorBinding
1980+
@ConfigurationProperties("test")
19771981
static class NestedConstructorProperties {
19781982

19791983
private final String name;
@@ -2033,7 +2037,8 @@ static class DeducedNestedConstructorPropertiesConfiguration {
20332037

20342038
}
20352039

2036-
@ImmutableConfigurationProperties("test")
2040+
@ConstructorBinding
2041+
@ConfigurationProperties("test")
20372042
static class DeducedNestedConstructorProperties {
20382043

20392044
private final String name;

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesRegistrarTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ static class FooProperties {
128128

129129
}
130130

131-
@ImmutableConfigurationProperties(prefix = "bar")
131+
@ConstructorBinding
132+
@ConfigurationProperties(prefix = "bar")
132133
static class BarProperties {
133134

134135
BarProperties(String foo) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/scan/valid/ConfigurationPropertiesScanConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import org.springframework.boot.context.properties.ConfigurationProperties;
1919
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
20+
import org.springframework.boot.context.properties.ConstructorBinding;
2021
import org.springframework.boot.context.properties.EnableConfigurationProperties;
21-
import org.springframework.boot.context.properties.ImmutableConfigurationProperties;
2222
import org.springframework.boot.context.properties.scan.valid.b.BScanConfiguration;
2323

2424
/**
@@ -46,7 +46,8 @@ static class FooProperties {
4646

4747
}
4848

49-
@ImmutableConfigurationProperties(prefix = "bar")
49+
@ConstructorBinding
50+
@ConfigurationProperties(prefix = "bar")
5051
static class BarProperties {
5152

5253
BarProperties(String foo) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/scan/valid/b/BScanConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package org.springframework.boot.context.properties.scan.valid.b;
1717

1818
import org.springframework.boot.context.properties.ConfigurationProperties;
19-
import org.springframework.boot.context.properties.ImmutableConfigurationProperties;
19+
import org.springframework.boot.context.properties.ConstructorBinding;
2020

2121
/**
2222
* @author Madhura Bhave
@@ -28,7 +28,8 @@ public interface BProperties {
2828

2929
}
3030

31-
@ImmutableConfigurationProperties(prefix = "b.first")
31+
@ConstructorBinding
32+
@ConfigurationProperties(prefix = "b.first")
3233
public static class BFirstProperties implements BProperties {
3334

3435
private final String name;

spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/context/properties/KotlinConfigurationPropertiesBeanRegistrarTests.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class KotlinConfigurationPropertiesBeanRegistrarTests {
4747
@ConfigurationProperties(prefix = "foo")
4848
class FooProperties
4949

50-
@ImmutableConfigurationProperties(prefix = "bar")
50+
@ConstructorBinding
51+
@ConfigurationProperties(prefix = "bar")
5152
class BarProperties(val name: String?, val counter: Int = 42)
5253

5354
@ConfigurationProperties(prefix = "bing")

0 commit comments

Comments
 (0)