mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:35:50 +00:00
Display at startup Spring active profiles
This commit is contained in:
parent
40c3c6aa46
commit
f92c31c31a
1 changed files with 31 additions and 0 deletions
|
@ -1,10 +1,41 @@
|
||||||
package org.springframework.samples.petclinic.config;
|
package org.springframework.samples.petclinic.config;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({BusinessConfig.class, ToolsConfig.class})
|
@Import({BusinessConfig.class, ToolsConfig.class})
|
||||||
public class RootApplicationContextConfig {
|
public class RootApplicationContextConfig {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(RootApplicationContextConfig.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Environment env;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application custom initialization code.
|
||||||
|
* <p/>
|
||||||
|
* Spring profiles can be configured with a system property
|
||||||
|
* -Dspring.profiles.active=javaee
|
||||||
|
* <p/>
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void initApp() {
|
||||||
|
LOG.debug("Looking for Spring profiles...");
|
||||||
|
if (env.getActiveProfiles().length == 0) {
|
||||||
|
LOG.info("No Spring profile configured, running with default configuration.");
|
||||||
|
} else {
|
||||||
|
for (String profile : env.getActiveProfiles()) {
|
||||||
|
LOG.info("Detected Spring profile: {}", profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue