Added sample code for BAEL-1122 (#6468)
This commit is contained in:
parent
2c4d334dc3
commit
8f54420e95
@ -1,5 +1,5 @@
|
||||
<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>
|
||||
<artifactId>spring-all</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
@ -47,12 +47,16 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-websocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-messaging</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
<version>${annotation-api.version}</version>
|
||||
</dependency>
|
||||
<!-- aspectj -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
@ -227,13 +231,13 @@
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
|
||||
<properties>
|
||||
<start-class>org.baeldung.sample.App</start-class>
|
||||
<!-- Spring -->
|
||||
<org.springframework.version>5.0.6.RELEASE</org.springframework.version>
|
||||
<org.springframework.shell.version>1.2.0.RELEASE</org.springframework.shell.version>
|
||||
|
||||
<annotation-api.version>1.3.2</annotation-api.version>
|
||||
<!-- persistence -->
|
||||
<hibernate.version>5.2.5.Final</hibernate.version>
|
||||
|
||||
|
@ -7,6 +7,7 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:foo.properties")
|
||||
@PropertySource("classpath:bar.properties")
|
||||
public class PropertiesWithJavaConfig {
|
||||
|
||||
public PropertiesWithJavaConfig() {
|
||||
|
@ -7,7 +7,7 @@
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"
|
||||
>
|
||||
|
||||
<context:property-placeholder location="classpath:foo.properties"/>
|
||||
<context:property-placeholder location="classpath:foo.properties,classpath:bar.properties"/>
|
||||
|
||||
<bean id="componentInXmlUsingProperties" class="org.baeldung.properties.core.ComponentInXmlUsingProperties">
|
||||
<constructor-arg value="${key.something}"/>
|
||||
|
@ -0,0 +1,25 @@
|
||||
package org.baeldung.properties.multiple;
|
||||
|
||||
import org.baeldung.properties.spring.PropertiesWithJavaConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringJUnitConfig(PropertiesWithJavaConfig.class)
|
||||
public class MultiplePropertiesJavaConfigIntegrationTest {
|
||||
|
||||
@Value("${key.something}")
|
||||
private String something;
|
||||
|
||||
@Value("${key.something2}")
|
||||
private String something2;
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadInjectedValues_thenGetCorrectValues() {
|
||||
assertThat(something).isEqualTo("val");
|
||||
assertThat(something2).isEqualTo("val2");
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package org.baeldung.properties.multiple;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringJUnitConfig(locations = "classpath:configForProperties.xml")
|
||||
public class MultiplePropertiesXmlConfigIntegrationTest {
|
||||
|
||||
@Value("${key.something}") private String something;
|
||||
|
||||
@Value("${key.something2}") private String something2;
|
||||
|
||||
@Test
|
||||
public void whenReadInjectedValues_thenGetCorrectValues() {
|
||||
assertThat(something).isEqualTo("val");
|
||||
assertThat(something2).isEqualTo("val2");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user