Merge pull request #10421 from rozagerardo/rozagerardo/JAVA-3717_Update-articles-for-2.4.0--other-properties-modules
[JAVA-3717] Update articles for 2.4.0 - other properties-related articles
This commit is contained in:
commit
119af2bcb9
|
@ -33,6 +33,17 @@
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -26,12 +26,6 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.junit.vintage</groupId>
|
|
||||||
<artifactId>junit-vintage-engine</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
spring.datasource.password: 'password'
|
||||||
|
spring.datasource.url: jdbc:mysql://localhost:3306/db_integration
|
||||||
|
spring.datasource.username: user
|
||||||
|
bael.property=integrationValue
|
|
@ -9,3 +9,17 @@ spring.datasource.username=SA
|
||||||
spring.datasource.password=password
|
spring.datasource.password=password
|
||||||
app.name=MyApp
|
app.name=MyApp
|
||||||
app.description=${app.name} is a Spring Boot application
|
app.description=${app.name} is a Spring Boot application
|
||||||
|
logging.file.name=myapplication.log
|
||||||
|
bael.property=defaultValue
|
||||||
|
#---
|
||||||
|
spring.config.activate.on-profile=multidocument-dev
|
||||||
|
spring.datasource.password=password
|
||||||
|
spring.datasource.url=jdbc:h2:dev
|
||||||
|
spring.datasource.username=SA
|
||||||
|
bael.property=devValue
|
||||||
|
#---
|
||||||
|
spring.config.activate.on-profile=multidocument-prod
|
||||||
|
spring.datasource.password=password
|
||||||
|
spring.datasource.url=jdbc:h2:prod
|
||||||
|
spring.datasource.username=prodUser
|
||||||
|
bael.property=prodValue
|
|
@ -1,17 +1,17 @@
|
||||||
logging:
|
bael:
|
||||||
file:
|
root-level-property: defaultRootLevelValue
|
||||||
name: myapplication.log
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
password: 'password'
|
|
||||||
url: jdbc:h2:dev
|
|
||||||
username: SA
|
|
||||||
---
|
---
|
||||||
spring:
|
spring:
|
||||||
|
config:
|
||||||
|
activate:
|
||||||
|
on-profile: multidocument-staging
|
||||||
datasource:
|
datasource:
|
||||||
password: 'password'
|
password: 'password'
|
||||||
url: jdbc:mysql://localhost:3306/db_production
|
url: jdbc:h2:staging
|
||||||
username: user
|
username: SA
|
||||||
|
bael:
|
||||||
|
property: stagingValue
|
||||||
|
---
|
||||||
application:
|
application:
|
||||||
servers:
|
servers:
|
||||||
- ip: '127.0.0.1'
|
- ip: '127.0.0.1'
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.baeldung.boot.properties.multidocument;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
|
|
||||||
|
import com.baeldung.boot.properties.DemoApplication;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||||
|
public class DefaultMultidocumentFilesIntegrationTest {
|
||||||
|
|
||||||
|
@Value("${bael.property}")
|
||||||
|
private String baelCustomProperty;
|
||||||
|
|
||||||
|
@Value("${bael.root-level-property}")
|
||||||
|
private String baelRootProperty;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDefaultProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() {
|
||||||
|
assertThat(baelCustomProperty).isEqualTo("defaultValue");
|
||||||
|
assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.baeldung.boot.properties.multidocument;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import com.baeldung.boot.properties.DemoApplication;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||||
|
@ActiveProfiles("multidocument-dev")
|
||||||
|
public class DevMultidocumentFilesIntegrationTest {
|
||||||
|
|
||||||
|
@Value("${bael.property}")
|
||||||
|
private String baelCustomProperty;
|
||||||
|
|
||||||
|
@Value("${bael.root-level-property}")
|
||||||
|
private String baelRootProperty;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDefaultProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() {
|
||||||
|
assertThat(baelCustomProperty).isEqualTo("devValue");
|
||||||
|
assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.baeldung.boot.properties.multidocument;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import com.baeldung.boot.properties.DemoApplication;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||||
|
@ActiveProfiles("multidocument-integration")
|
||||||
|
public class IntegrationMultidocumentFilesIntegrationTest {
|
||||||
|
|
||||||
|
@Value("${bael.property}")
|
||||||
|
private String baelCustomProperty;
|
||||||
|
|
||||||
|
@Value("${bael.root-level-property}")
|
||||||
|
private String baelRootProperty;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() {
|
||||||
|
assertThat(baelCustomProperty).isEqualTo("integrationValue");
|
||||||
|
assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.baeldung.boot.properties.multidocument;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import com.baeldung.boot.properties.DemoApplication;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||||
|
@ActiveProfiles("multidocument-prod")
|
||||||
|
public class ProdMultidocumentFilesIntegrationTest {
|
||||||
|
|
||||||
|
@Value("${bael.property}")
|
||||||
|
private String baelCustomProperty;
|
||||||
|
|
||||||
|
@Value("${bael.root-level-property}")
|
||||||
|
private String baelRootProperty;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() {
|
||||||
|
assertThat(baelCustomProperty).isEqualTo("prodValue");
|
||||||
|
assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.baeldung.boot.properties.multidocument;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import com.baeldung.boot.properties.DemoApplication;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = { DemoApplication.class }, webEnvironment = WebEnvironment.MOCK)
|
||||||
|
@ActiveProfiles("multidocument-staging")
|
||||||
|
public class StagingMultidocumentFilesIntegrationTest {
|
||||||
|
|
||||||
|
@Value("${bael.property}")
|
||||||
|
private String baelCustomProperty;
|
||||||
|
|
||||||
|
@Value("${bael.root-level-property}")
|
||||||
|
private String baelRootProperty;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenProductionProfileActive_whenApplicationStarts_thenDefaultPropertiesUser() {
|
||||||
|
assertThat(baelCustomProperty).isEqualTo("stagingValue");
|
||||||
|
assertThat(baelRootProperty).isEqualTo("defaultRootLevelValue");
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,6 +51,17 @@
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Embedded Redis Server -->
|
<!-- Embedded Redis Server -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -7,13 +7,13 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
|
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class)
|
@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class)
|
||||||
@EnableConfigurationProperties(value = ServerConfig.class)
|
@EnableConfigurationProperties(value = ServerConfig.class)
|
||||||
@ActiveProfiles("test")
|
@ActiveProfiles("test")
|
||||||
public class BindingYMLPropertiesUnitTest {
|
public class BindingYMLPropertiesUnitTest {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
|
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer;
|
||||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
@ -19,7 +19,7 @@ import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = { ApplicationCommandLineRunnerApp.class },
|
@ContextConfiguration(classes = { ApplicationCommandLineRunnerApp.class },
|
||||||
initializers = ConfigFileApplicationContextInitializer.class)
|
initializers = ConfigDataApplicationContextInitializer.class)
|
||||||
public class LoadSpringContextIntegrationTest {
|
public class LoadSpringContextIntegrationTest {
|
||||||
@SpyBean
|
@SpyBean
|
||||||
TaskService taskService;
|
TaskService taskService;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
spring:
|
spring:
|
||||||
profiles: test
|
config:
|
||||||
|
activate:
|
||||||
|
on-profile: test
|
||||||
server:
|
server:
|
||||||
address:
|
address:
|
||||||
ip: 192.168.0.4
|
ip: 192.168.0.4
|
||||||
|
@ -7,7 +9,9 @@ server:
|
||||||
imgs: /etc/test/imgs
|
imgs: /etc/test/imgs
|
||||||
---
|
---
|
||||||
spring:
|
spring:
|
||||||
profiles: dev
|
config:
|
||||||
|
activate:
|
||||||
|
on-profile: dev
|
||||||
server:
|
server:
|
||||||
address:
|
address:
|
||||||
ip: 192.168.0.5
|
ip: 192.168.0.5
|
||||||
|
|
|
@ -39,6 +39,17 @@
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
|
|
Loading…
Reference in New Issue