There are at least 4 ways of having immutable properties loaded from configuration:
@ConfigurationProperties("acme")
public class AcmeJavaClassProperties {
private final boolean enabled;
private final String text;
private final List<String> list;
private final float number;
public AcmeJavaClassProperties(
boolean enabled,
String text,
List<String> list,
float number
) {
this.enabled = enabled;
this.text = text;
this.list = unmodifiableList(list);
this.number = number;
}
}
@ConfigurationProperties("acme")
public record AcmeJavaRecordProperties(
boolean enabled,
String text,
List<String> list,
float number
) {
}
@ConfigurationProperties("acme")
class AcmeKotlinClassProperties(
val enabled: Boolean,
val text: String,
val list: List<String>,
val number: Float
)
@ConfigurationProperties("acme")
data class AcmeKotlinDataClassProperties (
val enabled: Boolean,
val text: String,
val list: List<String>,
val number: Float
)
Note that since Spring Boot 3.x @ConstructorBinding annotation is only required to indicate which constructor to use in case there is more than one.
You can also browse older versions:
Review AcmeApplicationTest and ...
./gradlew test