Skip to content

Commit 446bf7f

Browse files
author
eugenp
committed
persistence work
1 parent 393c1ea commit 446bf7f

13 files changed

+98
-26
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.baeldung.properties.external;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.PropertySource;
7+
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
8+
9+
@Configuration
10+
@ComponentScan("org.baeldung.properties.core")
11+
@PropertySource("classpath:foo.properties")
12+
public class ExternalPropertiesWithJavaConfig {
13+
14+
public ExternalPropertiesWithJavaConfig() {
15+
super();
16+
}
17+
18+
// beans
19+
20+
@Bean
21+
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
22+
return new PropertySourcesPlaceholderConfigurer();
23+
}
24+
25+
}

spring-all/src/main/java/org/baeldung/properties/external/PropertiesWithXmlConfig.java renamed to spring-all/src/main/java/org/baeldung/properties/external/ExternalPropertiesWithXmlConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
@Configuration
88
@ImportResource("classpath:configForProperties.xml")
99
@ComponentScan("org.baeldung.core")
10-
public class PropertiesWithXmlConfig {
10+
public class ExternalPropertiesWithXmlConfig {
1111

12-
public PropertiesWithXmlConfig() {
12+
public ExternalPropertiesWithXmlConfig() {
1313
super();
1414
}
1515

spring-all/src/main/java/org/baeldung/properties/external/PropertiesWithXmlConfigOne.java renamed to spring-all/src/main/java/org/baeldung/properties/external/ExternalPropertiesWithXmlConfigOne.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
@Configuration
88
@ImportResource("classpath:configForPropertiesOne.xml")
99
@ComponentScan("org.baeldung.core")
10-
public class PropertiesWithXmlConfigOne {
10+
public class ExternalPropertiesWithXmlConfigOne {
1111

12-
public PropertiesWithXmlConfigOne() {
12+
public ExternalPropertiesWithXmlConfigOne() {
1313
super();
1414
}
1515

spring-all/src/main/java/org/baeldung/properties/external/PropertiesWithXmlConfigTwo.java renamed to spring-all/src/main/java/org/baeldung/properties/external/ExternalPropertiesWithXmlConfigTwo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
@Configuration
77
@ImportResource("classpath:basicConfigForPropertiesTwo.xml")
8-
public class PropertiesWithXmlConfigTwo {
8+
public class ExternalPropertiesWithXmlConfigTwo {
99

10-
public PropertiesWithXmlConfigTwo() {
10+
public ExternalPropertiesWithXmlConfigTwo() {
1111
super();
1212
}
1313

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package org.baeldung.properties.spring;
22

3-
import org.springframework.context.annotation.Bean;
43
import org.springframework.context.annotation.Configuration;
54
import org.springframework.context.annotation.PropertySource;
6-
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
75

86
@Configuration
97
@PropertySource("classpath:foo.properties")
@@ -13,11 +11,4 @@ public BasicPropertiesWithJavaConfig() {
1311
super();
1412
}
1513

16-
// beans
17-
18-
@Bean
19-
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
20-
return new PropertySourcesPlaceholderConfigurer();
21-
}
22-
2314
}

spring-all/src/main/java/org/baeldung/properties/external/PropertiesWithJavaConfig.java renamed to spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfig.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
package org.baeldung.properties.external;
1+
package org.baeldung.properties.spring;
22

33
import org.springframework.context.annotation.Bean;
4-
import org.springframework.context.annotation.ComponentScan;
54
import org.springframework.context.annotation.Configuration;
65
import org.springframework.context.annotation.PropertySource;
76
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
87

98
@Configuration
10-
@ComponentScan("org.baeldung.properties.core")
119
@PropertySource("classpath:foo.properties")
1210
public class PropertiesWithJavaConfig {
1311

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.baeldung.properties.basic;
2+
3+
import org.baeldung.properties.spring.BasicPropertiesWithJavaConfig;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.beans.factory.annotation.Value;
8+
import org.springframework.core.env.Environment;
9+
import org.springframework.test.context.ContextConfiguration;
10+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11+
import org.springframework.test.context.support.AnnotationConfigContextLoader;
12+
13+
@RunWith(SpringJUnit4ClassRunner.class)
14+
@ContextConfiguration(classes = { BasicPropertiesWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
15+
public class BasicPropertiesWithJavaIntegrationTest {
16+
17+
@Autowired
18+
private Environment env;
19+
20+
@Value("${key.something}")
21+
private String injectedProperty;
22+
23+
@Test
24+
public final void givenContextIsInitialized_thenNoException() {
25+
System.out.println("in test via @Value: " + injectedProperty);
26+
System.out.println("in test Environment: " + env.getProperty("key.something"));
27+
}
28+
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.baeldung.properties.basic;
2+
3+
import org.baeldung.properties.spring.BasicPropertiesWithJavaConfig;
4+
import org.baeldung.properties.spring.PropertiesWithJavaConfigOther;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.core.env.Environment;
10+
import org.springframework.test.context.ContextConfiguration;
11+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12+
import org.springframework.test.context.support.AnnotationConfigContextLoader;
13+
14+
@RunWith(SpringJUnit4ClassRunner.class)
15+
@ContextConfiguration(classes = { BasicPropertiesWithJavaConfig.class, PropertiesWithJavaConfigOther.class }, loader = AnnotationConfigContextLoader.class)
16+
public class ExtendedPropertiesWithJavaIntegrationTest {
17+
18+
@Autowired
19+
private Environment env;
20+
21+
@Value("${key.something}")
22+
private String injectedProperty;
23+
24+
@Test
25+
public final void givenContextIsInitialized_thenNoException() {
26+
System.out.println("in test via @Value: " + injectedProperty);
27+
System.out.println("in test Environment: " + env.getProperty("key.something"));
28+
}
29+
30+
}

spring-all/src/test/java/org/baeldung/properties/basic/PropertiesWithJavaIntegrationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.baeldung.properties.basic;
22

3-
import org.baeldung.properties.spring.BasicPropertiesWithJavaConfig;
4-
import org.baeldung.properties.spring.PropertiesWithJavaConfigOther;
3+
import org.baeldung.properties.spring.PropertiesWithJavaConfig;
54
import org.junit.Test;
65
import org.junit.runner.RunWith;
76
import org.springframework.beans.factory.annotation.Autowired;
@@ -12,7 +11,7 @@
1211
import org.springframework.test.context.support.AnnotationConfigContextLoader;
1312

1413
@RunWith(SpringJUnit4ClassRunner.class)
15-
@ContextConfiguration(classes = { BasicPropertiesWithJavaConfig.class, PropertiesWithJavaConfigOther.class }, loader = AnnotationConfigContextLoader.class)
14+
@ContextConfiguration(classes = { PropertiesWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
1615
public class PropertiesWithJavaIntegrationTest {
1716

1817
@Autowired

spring-all/src/test/java/org/baeldung/properties/external/ExternalPropertiesWithJavaIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.springframework.test.context.support.AnnotationConfigContextLoader;
1313

1414
@RunWith(SpringJUnit4ClassRunner.class)
15-
@ContextConfiguration(classes = { PropertiesWithJavaConfig.class, PropertiesWithJavaConfigOther.class }, loader = AnnotationConfigContextLoader.class)
15+
@ContextConfiguration(classes = { ExternalPropertiesWithJavaConfig.class, PropertiesWithJavaConfigOther.class }, loader = AnnotationConfigContextLoader.class)
1616
@Ignore("manual only")
1717
public class ExternalPropertiesWithJavaIntegrationTest {
1818

0 commit comments

Comments
 (0)