Feature/bael 2077 dhawal (#5232)

* [BAEL-2077] - Add section in Spring Profiles article

* removed irrelevent code

* [BAEL-2077] - Removing unnecessory files and adding Integration test file
This commit is contained in:
Dhawal Kapil 2018-09-13 11:09:53 +05:30 committed by Predrag Maric
parent 88601730d0
commit 72e1e9634b
4 changed files with 43 additions and 1 deletions

View File

@ -190,7 +190,24 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
</profile>
</profiles>
<properties>
<start-class>org.baeldung.sample.App</start-class>
<!-- Spring -->

View File

@ -2,9 +2,11 @@ package org.baeldung.profiles;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@ComponentScan("org.baeldung.profiles")
@PropertySource(value = "classpath:application.properties")
public class SpringProfilesConfig {
}

View File

@ -0,0 +1 @@
spring.profiles.active=@spring.profiles.active@

View File

@ -0,0 +1,22 @@
package org.baeldung.profiles;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SpringProfilesConfig.class }, loader = AnnotationConfigContextLoader.class)
public class SpringProfilesWithMavenPropertiesIntegrationTest {
@Autowired
DatasourceConfig datasourceConfig;
@Test
public void testSpringProfiles() {
Assert.assertTrue(datasourceConfig instanceof DevDatasourceConfig);
}
}