How to get Spring to print out what spring profiles are active?
java, spring
Solution
Implement `EnvironmentAware` interface
For example
class MyEnvironmentAware implements EnvironmentAware{
private static Environment env = null;
@Override
public void setEnvironment(Environment environment) {
env = environment;
//log the stuff you want here
}
}
Mark this class as Spring bean
or
just inject `Environment` in one of your eagerly loading bean and print the detail you need from it
like
@Autowired
Environment env;
in your eagerly loading bean, and print it
Problem
I am using spring 3.1 profiles and want would like Spring to print out on startup what profiles are active. For example are the first few lines of the output in the log file. ``` 02:59:43,451 INFO [ContextLoader] Root WebApplicationContext: initialization started 02:59:43,544 INFO [XmlWebApplicationContext] Refreshing Root WebApplicationContext: startup date [Sun Dec 30 02:59:43 EST 2012]; root of context hierarchy 02:59:43,610 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [spring.xml] 02:59:43,835 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [spring-security.xml] 02:59:43,971 INFO [SpringSecurityCoreVersion] You are running with Spring Security Core 3.1.3.RELEASE 02:59:43,971 INFO [SecurityNamespaceHandler] Spring Security 'config' module version is 3.1.3.RELEASE ``` What I want to see from spring is something that prints out the version of spring in use along with which profiles are currently active. How can I get spring to printout it's version and what profiles are active?