Skip to content

Commit 72e1e96

Browse files
dkapilpedja4
authored andcommitted
Feature/bael 2077 dhawal (eugenp#5232)
* [BAEL-2077] - Add section in Spring Profiles article * removed irrelevent code * [BAEL-2077] - Removing unnecessory files and adding Integration test file
1 parent 8860173 commit 72e1e96

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎spring-all/pom.xml‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,24 @@
190190
</plugin>
191191
</plugins>
192192
</build>
193-
193+
<profiles>
194+
<profile>
195+
<id>dev</id>
196+
<activation>
197+
<activeByDefault>true</activeByDefault>
198+
</activation>
199+
<properties>
200+
<spring.profiles.active>dev</spring.profiles.active>
201+
</properties>
202+
</profile>
203+
<profile>
204+
<id>prod</id>
205+
<properties>
206+
<spring.profiles.active>prod</spring.profiles.active>
207+
</properties>
208+
</profile>
209+
</profiles>
210+
194211
<properties>
195212
<start-class>org.baeldung.sample.App</start-class>
196213
<!-- Spring -->

‎spring-all/src/main/java/org/baeldung/profiles/SpringProfilesConfig.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import org.springframework.context.annotation.ComponentScan;
44
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.context.annotation.PropertySource;
56

67
@Configuration
78
@ComponentScan("org.baeldung.profiles")
9+
@PropertySource(value = "classpath:application.properties")
810
public class SpringProfilesConfig {
911

1012
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.profiles.active=@spring.profiles.active@
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.baeldung.profiles;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.test.context.ContextConfiguration;
8+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9+
import org.springframework.test.context.support.AnnotationConfigContextLoader;
10+
11+
@RunWith(SpringJUnit4ClassRunner.class)
12+
@ContextConfiguration(classes = { SpringProfilesConfig.class }, loader = AnnotationConfigContextLoader.class)
13+
public class SpringProfilesWithMavenPropertiesIntegrationTest {
14+
15+
@Autowired
16+
DatasourceConfig datasourceConfig;
17+
18+
@Test
19+
public void testSpringProfiles() {
20+
Assert.assertTrue(datasourceConfig instanceof DevDatasourceConfig);
21+
}
22+
}

0 commit comments

Comments
 (0)