JAVA-18600 Update "Guide to @ConfigurationProperties in Spring Boot" … (#13670)

* JAVA-18600 Update "Guide to @ConfigurationProperties in Spring Boot" article

---------

Co-authored-by: timis1 <[email protected]>
This commit is contained in:
timis1
2023-04-13 16:18:11 +03:00
committed by GitHub
co-authored by timis1
parent d964c3d1eb
commit fae3e80186
13 changed files with 73 additions and 62 deletions
@@ -10,9 +10,10 @@
<description>Spring Boot Properties Module</description>
<parent>
<groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>spring-boot-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent>
<dependencies>
@@ -24,6 +25,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<properties>
<start-class>com.baeldung.properties.yaml.YamlApplication</start-class>
</properties>
</project>
@@ -7,11 +7,12 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import jakarta.annotation.PostConstruct;
@Configuration
@PropertySource(name = "myProperties", value = "values.properties")
public class ValuesApp {
@@ -1,6 +1,6 @@
package com.baeldung.properties.value.defaults;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -8,10 +8,11 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.util.Assert;
import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.List;
import jakarta.annotation.PostConstruct;
/**
* Demonstrates setting defaults for @Value annotation. Note that there are no properties
* defined in the specified property source. We also assume that the user here
@@ -60,10 +61,10 @@ public class ValuesWithDefaultsApp {
// arrays
List<String> stringListValues = Arrays.asList("one", "two", "three");
Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues), "unexpected value for stringArrayWithDefaults");
Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues), "unexpected value for stringArrayWithDefaults");
List<Integer> intListValues = Arrays.asList(1, 2, 3);
Assert.isTrue(Arrays.asList(ArrayUtils.toObject(intArrayWithDefaults)).containsAll(intListValues), "unexpected value for intArrayWithDefaults");
Assert.isTrue(Arrays.asList(ArrayUtils.toObject(intArrayWithDefaults)).containsAll(intListValues), "unexpected value for intArrayWithDefaults");
// SpEL
Assert.isTrue(spelWithDefaultValue.equals("my default system property value"), "unexpected value for spelWithDefaultValue");