Improved spring-properties-file-outside-jar with new 2.4.0 feature

This commit is contained in:
Gerardo Roza 2021-01-15 16:00:03 -03:00
parent 1c5185b549
commit 6b462cd6c6
4 changed files with 42 additions and 7 deletions

View File

@ -0,0 +1 @@
bael.property1=value1

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -88,7 +89,6 @@
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId> <artifactId>spring-cloud-context</artifactId>
<version>${springcloud.version}</version>
</dependency> </dependency>
<dependency> <dependency>
@ -99,6 +99,18 @@
</dependencies> </dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build> <build>
<finalName>${project.artifactId}</finalName> <finalName>${project.artifactId}</finalName>
<resources> <resources>
@ -153,9 +165,8 @@
<jpa.version>2.2</jpa.version> <jpa.version>2.2</jpa.version>
<guava.version>18.0</guava.version> <guava.version>18.0</guava.version>
<subethasmtp.version>3.1.7</subethasmtp.version> <subethasmtp.version>3.1.7</subethasmtp.version>
<springcloud.version>2.0.2.RELEASE</springcloud.version>
<httpclient.version>4.5.8</httpclient.version> <httpclient.version>4.5.8</httpclient.version>
<spring-boot.version>2.3.3.RELEASE</spring-boot.version> <spring.cloud-version>2020.0.0</spring.cloud-version>
</properties> </properties>
</project> </project>

View File

@ -2,6 +2,7 @@ management.endpoints.web.exposure.include=*
management.metrics.enable.root=true management.metrics.enable.root=true
management.metrics.enable.jvm=true management.metrics.enable.jvm=true
management.endpoint.restart.enabled=true management.endpoint.restart.enabled=true
spring.datasource.jmx-enabled=false spring.datasource.tomcat.jmx-enabled=false
spring.main.allow-bean-definition-overriding=true spring.main.allow-bean-definition-overriding=true
management.endpoint.shutdown.enabled=true management.endpoint.shutdown.enabled=true
spring.config.import=file:./additional.properties,optional:file:/Users/home/config/jdbc.properties

View File

@ -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");
}
}