diff --git a/spring-boot-modules/spring-boot-environment/additional.properties b/spring-boot-modules/spring-boot-environment/additional.properties new file mode 100644 index 0000000000..676536efa5 --- /dev/null +++ b/spring-boot-modules/spring-boot-environment/additional.properties @@ -0,0 +1 @@ +bael.property1=value1 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-environment/pom.xml b/spring-boot-modules/spring-boot-environment/pom.xml index e3a8186cbf..a3aab63a2d 100644 --- a/spring-boot-modules/spring-boot-environment/pom.xml +++ b/spring-boot-modules/spring-boot-environment/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -88,7 +89,6 @@ org.springframework.cloud spring-cloud-context - ${springcloud.version} @@ -99,6 +99,18 @@ + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring.cloud-version} + pom + import + + + + ${project.artifactId} @@ -153,9 +165,8 @@ 2.2 18.0 3.1.7 - 2.0.2.RELEASE 4.5.8 - 2.3.3.RELEASE + 2020.0.0 diff --git a/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties b/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties index 27b7915cff..3d6f37230c 100644 --- a/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-environment/src/main/resources/application.properties @@ -2,6 +2,7 @@ management.endpoints.web.exposure.include=* management.metrics.enable.root=true management.metrics.enable.jvm=true management.endpoint.restart.enabled=true -spring.datasource.jmx-enabled=false +spring.datasource.tomcat.jmx-enabled=false spring.main.allow-bean-definition-overriding=true -management.endpoint.shutdown.enabled=true \ No newline at end of file +management.endpoint.shutdown.enabled=true +spring.config.import=file:./additional.properties,optional:file:/Users/home/config/jdbc.properties \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java b/spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java new file mode 100644 index 0000000000..04f5445639 --- /dev/null +++ b/spring-boot-modules/spring-boot-environment/src/test/java/com/baeldung/properties/ApplicationPropertyImportExternalFileIntegrationTest.java @@ -0,0 +1,22 @@ +package com.baeldung.properties; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class ApplicationPropertyImportExternalFileIntegrationTest { + + @Value("${bael.property1}") + String baelProperty; + + @Test + public void whenExternalisedPropertiesLoadedUsinApplicationProperties_thenReadValues() throws IOException { + assertEquals(baelProperty, "value1"); + } + +}