diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 83b935f845..1de19fc867 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -63,10 +63,6 @@ spring-boot-nashorn spring-boot-parent spring-boot-performance - spring-boot-properties - spring-boot-properties-2 - spring-boot-properties-3 - spring-boot-properties-migrator-demo spring-boot-property-exp spring-boot-request-params spring-boot-runtime @@ -94,6 +90,10 @@ spring-boot-3-observation spring-boot-3-test-pitfalls spring-boot-resilience4j + spring-boot-properties + spring-boot-properties-2 + spring-boot-properties-3 + spring-boot-properties-migrator-demo diff --git a/spring-boot-modules/spring-boot-properties-2/pom.xml b/spring-boot-modules/spring-boot-properties-2/pom.xml index 442cb24c7a..4b1daca34d 100644 --- a/spring-boot-modules/spring-boot-properties-2/pom.xml +++ b/spring-boot-modules/spring-boot-properties-2/pom.xml @@ -10,9 +10,10 @@ Spring Boot Properties Module - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -24,6 +25,15 @@ org.springframework.boot spring-boot-starter-web + + commons-lang + commons-lang + 2.6 + + + com.baeldung.properties.yaml.YamlApplication + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/ValuesApp.java b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/ValuesApp.java index 67547199a6..282ce4658e 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/ValuesApp.java +++ b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/ValuesApp.java @@ -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 { diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java index 2a2b535be7..f1720d2fb3 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java +++ b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/value/defaults/ValuesWithDefaultsApp.java @@ -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 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 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"); diff --git a/spring-boot-modules/spring-boot-properties-3/pom.xml b/spring-boot-modules/spring-boot-properties-3/pom.xml index 3de85c7175..ed6e08add0 100644 --- a/spring-boot-modules/spring-boot-properties-3/pom.xml +++ b/spring-boot-modules/spring-boot-properties-3/pom.xml @@ -9,9 +9,10 @@ Spring Boot Properties Module - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -31,7 +32,6 @@ org.springframework.boot spring-boot-starter-web - RELEASE @@ -44,4 +44,8 @@ + + com.baeldung.boot.properties.DemoApplication + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/log/EnvironmentPropertiesPrinter.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/log/EnvironmentPropertiesPrinter.java index 321593b31b..26f6867296 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/log/EnvironmentPropertiesPrinter.java +++ b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/log/EnvironmentPropertiesPrinter.java @@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; @Component public class EnvironmentPropertiesPrinter { diff --git a/spring-boot-modules/spring-boot-properties-migrator-demo/pom.xml b/spring-boot-modules/spring-boot-properties-migrator-demo/pom.xml index 95dc06b155..21ed0f59f4 100644 --- a/spring-boot-modules/spring-boot-properties-migrator-demo/pom.xml +++ b/spring-boot-modules/spring-boot-properties-migrator-demo/pom.xml @@ -7,10 +7,10 @@ 1.0-SNAPSHOT - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT - ../pom.xml + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -49,8 +49,8 @@ - 8 - 8 + 17 + 17 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/pom.xml b/spring-boot-modules/spring-boot-properties/pom.xml index 0d076581b7..4ad5aeed1d 100644 --- a/spring-boot-modules/spring-boot-properties/pom.xml +++ b/spring-boot-modules/spring-boot-properties/pom.xml @@ -10,9 +10,10 @@ Spring Boot Properties Module - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -141,7 +142,7 @@ - 2021.0.3 + 2022.0.1 1.10 @ diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ConfigProperties.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ConfigProperties.java index 47df784885..faf5678398 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ConfigProperties.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ConfigProperties.java @@ -3,10 +3,10 @@ package com.baeldung.configurationproperties; import java.util.List; import java.util.Map; -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Pattern; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; import org.hibernate.validator.constraints.Length; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ImmutableCredentials.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ImmutableCredentials.java index a58e4143e5..72c45afbb2 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ImmutableCredentials.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/configurationproperties/ImmutableCredentials.java @@ -1,10 +1,8 @@ package com.baeldung.configurationproperties; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.ConstructorBinding; @ConfigurationProperties(prefix = "mail.credentials") -@ConstructorBinding public class ImmutableCredentials { private final String authMethod; diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/buildproperties/BuildInfoServiceIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/buildproperties/BuildInfoServiceIntegrationTest.java index 2cb27e1844..9ed27f412c 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/buildproperties/BuildInfoServiceIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/buildproperties/BuildInfoServiceIntegrationTest.java @@ -4,12 +4,9 @@ import static org.junit.Assert.assertThat; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) class BuildInfoServiceIntegrationTest { diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/buildproperties/BuildPropertiesUnitTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/buildproperties/BuildPropertiesUnitTest.java index cf9b9336e6..bb8ec78cc1 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/buildproperties/BuildPropertiesUnitTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/buildproperties/BuildPropertiesUnitTest.java @@ -17,7 +17,7 @@ public class BuildPropertiesUnitTest { @Test void givenBuildPropertiesBean_WhenFetchDefaultBuildProperties_ThenGetValidValues() { Assertions.assertEquals("spring-boot-properties", buildProperties.getArtifact()); - Assertions.assertEquals("com.baeldung.spring-boot-modules", buildProperties.getGroup()); + Assertions.assertEquals("com.baeldung", buildProperties.getGroup()); Assertions.assertEquals("0.0.1-SNAPSHOT", buildProperties.getVersion()); } diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/reloading/PropertiesReloadManualTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/reloading/PropertiesReloadManualTest.java index 88e22af4ba..ecb547a0a0 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/reloading/PropertiesReloadManualTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/reloading/PropertiesReloadManualTest.java @@ -1,28 +1,27 @@ package com.baeldung.properties.reloading; +import static org.junit.jupiter.api.Assertions.assertEquals; + import com.baeldung.properties.reloading.beans.ConfigurationPropertiesRefreshConfigBean; import com.baeldung.properties.reloading.beans.EnvironmentConfigBean; import com.baeldung.properties.reloading.beans.PropertiesConfigBean; import com.baeldung.properties.reloading.beans.ValueRefreshConfigBean; import java.io.FileOutputStream; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = SpringBootPropertiesTestApplication.class) public class PropertiesReloadManualTest { @@ -50,7 +49,7 @@ public class PropertiesReloadManualTest { ValueRefreshConfigBean singletonValueRefreshConfigBean; - @Before + @BeforeEach public void setUp() throws Exception { mvc = MockMvcBuilders .webAppContextSetup(webApplicationContext) @@ -61,7 +60,7 @@ public class PropertiesReloadManualTest { callRefresh(); } - @After + @AfterEach public void tearDown() throws Exception { createConfig("extra.properties", "application.theme.color", "blue"); createConfig("extra2.properties", "application.theme.background", "red"); @@ -69,76 +68,76 @@ public class PropertiesReloadManualTest { @Test public void givenEnvironmentReader_whenColorChanged_thenExpectChangeValue() throws Exception { - Assert.assertEquals("blue", environmentConfigBean.getColor()); + assertEquals("blue", environmentConfigBean.getColor()); createConfig("extra.properties", "application.theme.color", "red"); Thread.sleep(refreshDelay); - Assert.assertEquals("red", environmentConfigBean.getColor()); + assertEquals("red", environmentConfigBean.getColor()); } @Test public void givenEnvironmentReader_whenBackgroundChanged_thenExpectChangeValue() throws Exception { - Assert.assertEquals("red", environmentConfigBean.getBackgroundColor()); + assertEquals("red", environmentConfigBean.getBackgroundColor()); createConfig("extra2.properties", "application.theme.background", "blue"); Thread.sleep(refreshDelay); - Assert.assertEquals("blue", environmentConfigBean.getBackgroundColor()); + assertEquals("blue", environmentConfigBean.getBackgroundColor()); } @Test public void givenPropertiesReader_whenColorChanged_thenExpectChangeValue() throws Exception { - Assert.assertEquals("blue", propertiesConfigBean.getColor()); + assertEquals("blue", propertiesConfigBean.getColor()); createConfig("extra.properties", "application.theme.color", "red"); Thread.sleep(refreshDelay); - Assert.assertEquals("red", propertiesConfigBean.getColor()); + assertEquals("red", propertiesConfigBean.getColor()); } @Test public void givenRefreshScopedValueReader_whenColorChangedAndRefreshCalled_thenExpectChangeValue() throws Exception { - Assert.assertEquals("blue", valueRefreshConfigBean.getColor()); + assertEquals("blue", valueRefreshConfigBean.getColor()); createConfig("extra.properties", "application.theme.color", "red"); Thread.sleep(refreshDelay); - Assert.assertEquals("blue", valueRefreshConfigBean.getColor()); + assertEquals("blue", valueRefreshConfigBean.getColor()); callRefresh(); - Assert.assertEquals("red", valueRefreshConfigBean.getColor()); + assertEquals("red", valueRefreshConfigBean.getColor()); } @Test public void givenSingletonRefreshScopedValueReader_whenColorChangedAndRefreshCalled_thenExpectOldValue() throws Exception { - Assert.assertEquals("blue", singletonValueRefreshConfigBean.getColor()); + assertEquals("blue", singletonValueRefreshConfigBean.getColor()); createConfig("extra.properties", "application.theme.color", "red"); Thread.sleep(refreshDelay); - Assert.assertEquals("blue", singletonValueRefreshConfigBean.getColor()); + assertEquals("blue", singletonValueRefreshConfigBean.getColor()); callRefresh(); - Assert.assertEquals("blue", singletonValueRefreshConfigBean.getColor()); + assertEquals("blue", singletonValueRefreshConfigBean.getColor()); } @Test public void givenRefreshScopedConfigurationPropertiesReader_whenColorChangedAndRefreshCalled_thenExpectChangeValue() throws Exception { - Assert.assertEquals("blue", configurationPropertiesRefreshConfigBean.getColor()); + assertEquals("blue", configurationPropertiesRefreshConfigBean.getColor()); createConfig("extra.properties", "application.theme.color", "red"); Thread.sleep(refreshDelay); - Assert.assertEquals("blue", configurationPropertiesRefreshConfigBean.getColor()); + assertEquals("blue", configurationPropertiesRefreshConfigBean.getColor()); callRefresh(); - Assert.assertEquals("red", configurationPropertiesRefreshConfigBean.getColor()); + assertEquals("red", configurationPropertiesRefreshConfigBean.getColor()); } public void callRefresh() throws Exception { @@ -148,7 +147,7 @@ public class PropertiesReloadManualTest { .accept(MediaType.APPLICATION_JSON_VALUE)) .andReturn(); MockHttpServletResponse response = mvcResult.getResponse(); - Assert.assertEquals(response.getStatus(), 200); + assertEquals(200, response.getStatus()); } public void createConfig(String file, String key, String value) throws Exception {