@PropertySource( value = "classpath:application-${spring.profiles.active}.properties" )
@PropertySource( value = "classpath:application.properties" )
maven, properties-maven-plugin (*)
<build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-active-profile-properties</goal>
</goals>
<configuration>
<outputFile>src/main/resources/application.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</build>
<profiles>
<profile>
<id>production</id>
<properties>
<profiles>prod</profiles>
<propertyOne>...</propertyOne>
<propertyTwo>...</propertyTwo>
</properties>
</profile>
<profile>
<id>development</id>
<properties>
<profiles>dev</profiles>
<propertyOne>...</propertyOne>
</properties>
</profile>
</profiles>
mvn <lifecycle> -P production
- maven?
:
@Configuration
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer
{
protected WebApplicationContext createRootApplicationContext() {
WebApplicationContext context = super.createRootApplicationContext();
((ConfigurableEnvironment) context.getEnvironment()).setActiveProfiles(profiles());
return context;
}
public String[] profiles() {
InputStream input = getClass().getClassLoader()
.getResourceAsStream("application.properties");
Properties properties = new Properties();
try {
properties.load(input);
return properties.getProperty("profiles").split(",");;
} catch (IOException e) {
e.printStackTrace();
String[] defaultProfiles = {"dev"};
return defaultProfiles;
}
}
}
(*) ( 2009), , , , , - + maven.