Added sample code for BAEL-1122 (#6468)

This commit is contained in:
Juan Moreno 2019-03-09 00:50:03 -03:00 committed by KevinGilmore
parent 2c4d334dc3
commit 8f54420e95
5 changed files with 59 additions and 8 deletions

View File

@ -52,7 +52,11 @@
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${annotation-api.version}</version>
</dependency>
<!-- aspectj -->
<dependency>
<groupId>org.springframework</groupId>
@ -233,7 +237,7 @@
<!-- 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>

View File

@ -7,6 +7,7 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@Configuration
@PropertySource("classpath:foo.properties")
@PropertySource("classpath:bar.properties")
public class PropertiesWithJavaConfig {
public PropertiesWithJavaConfig() {

View File

@ -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}"/>

View File

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

View File

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