Remove @ImmutableConfigurationProperties
Closes gh-18563
This commit is contained in:
@@ -849,10 +849,12 @@ The example in the previous section can be rewritten in an immutable fashion as
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ImmutableConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.ConstructorBinding;
|
||||
import org.springframework.boot.context.properties.DefaultValue;
|
||||
|
||||
@ImmutableConfigurationProperties("acme")
|
||||
@ConstructorBinding
|
||||
@ConfigurationProperties("acme")
|
||||
public class AcmeProperties {
|
||||
|
||||
private final boolean enabled;
|
||||
@@ -899,18 +901,17 @@ The example in the previous section can be rewritten in an immutable fashion as
|
||||
}
|
||||
----
|
||||
|
||||
In this setup, the `@ImmutableConfigurationProperties` annotation is used to indicate that constructor binding should be used.
|
||||
In this setup, the `@ConstructorBinding` annotation is used to indicate that constructor binding should be used.
|
||||
This means that the binder will expect to find a constructor with the parameters that you wish to have bound.
|
||||
|
||||
Nested members of a `@ImmutableConfigurationProperties` class (such as `Security` in the example above) will also be bound via their constructor.
|
||||
Nested members of a `@ConstructorBinding` class (such as `Security` in the example above) will also be bound via their constructor.
|
||||
|
||||
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.
|
||||
|
||||
NOTE: To use constructor binding the class must be enabled using `@EnableConfigurationProperties` or configuration property scanning.
|
||||
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`)
|
||||
|
||||
TIP: `@ImmutableConfigurationProperties` is actually a meta-annotation composed of `@ConfigurationProperties` and `@ConstructorBinding`.
|
||||
If you have more than one constructor for your class you can also use `@ConstructorBinding` directly on actual constructor that should be bound.
|
||||
TIP: If you have more than one constructor for your class you can also use `@ConstructorBinding` directly on the constructor that should be bound.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user