use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class CloudPlatformTests method getActiveWhenNotInCloudShouldReturnNull.
@Test
public void getActiveWhenNotInCloudShouldReturnNull() throws Exception {
Environment environment = new MockEnvironment();
CloudPlatform platform = CloudPlatform.getActive(environment);
assertThat(platform).isNull();
}
use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class EnvironmentEndpoint method getPropertySources.
private MutablePropertySources getPropertySources() {
MutablePropertySources sources;
Environment environment = getEnvironment();
if (environment != null && environment instanceof ConfigurableEnvironment) {
sources = ((ConfigurableEnvironment) environment).getPropertySources();
} else {
sources = new StandardEnvironment().getPropertySources();
}
return sources;
}
use of org.springframework.core.env.Environment in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurer method postProcessBeanFactory.
/**
* {@inheritDoc}
* <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
* against this configurer's set of {@link PropertySources}, which includes:
* <ul>
* <li>all {@linkplain org.springframework.core.env.ConfigurableEnvironment#getPropertySources
* environment property sources}, if an {@code Environment} {@linkplain #setEnvironment is present}
* <li>{@linkplain #mergeProperties merged local properties}, if {@linkplain #setLocation any}
* {@linkplain #setLocations have} {@linkplain #setProperties been}
* {@linkplain #setPropertiesArray specified}
* <li>any property sources set by calling {@link #setPropertySources}
* </ul>
* <p>If {@link #setPropertySources} is called, <strong>environment and local properties will be
* ignored</strong>. This method is designed to give the user fine-grained control over property
* sources, and once set, the configurer makes no assumptions about adding additional sources.
*/
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (this.propertySources == null) {
this.propertySources = new MutablePropertySources();
if (this.environment != null) {
this.propertySources.addLast(new PropertySource<Environment>(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
@Override
public String getProperty(String key) {
return this.source.getProperty(key);
}
});
}
try {
PropertySource<?> localPropertySource = new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, mergeProperties());
if (this.localOverride) {
this.propertySources.addFirst(localPropertySource);
} else {
this.propertySources.addLast(localPropertySource);
}
} catch (IOException ex) {
throw new BeanInitializationException("Could not load properties", ex);
}
}
processProperties(beanFactory, new PropertySourcesPropertyResolver(this.propertySources));
this.appliedPropertySources = this.propertySources;
}
use of org.springframework.core.env.Environment in project nikita-noark5-core by HiOA-ABI.
the class N5CoreApp method main.
/**
* Main method, used to run the application.
*
* @param args the command line arguments
* @throws UnknownHostException if the local host name could not be resolved into an address
*/
public static void main(final String... args) throws UnknownHostException {
//SpringApplication app = new SpringApplication(N5CoreApp.class);
//SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
ConfigurableApplicationContext context = SpringApplication.run(CONFIGS, args);
context.getBean(AfterApplicationStartup.class).afterApplicationStarts();
Environment env = context.getEnvironment();
String[] activeProfiles = env.getActiveProfiles();
String profilesAsString = Arrays.toString(activeProfiles);
logger.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t\thttp://localhost:{}\n\t" + "External: \t\thttp://{}:{}\n\t" + "contextPath: \thttp://{}:{}{} \n\t" + "Application is running with following profile(s): {} \n\t" + "\n----------------------------------------------------------", env.getProperty("spring.application.name"), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getProperty("server.contextPath"), profilesAsString);
String configServerStatus = env.getProperty("configserver.status");
logger.info("\n----------------------------------------------------------\n\t" + "Config Server: \t{}\n----------------------------------------------------------", configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
if (profilesAsString != null && profilesAsString.contains("de")) {
logger.info("\n----------------------------------------------------------\n\t" + "Dev/demo mode: In-memory database ({}) in use. See http://localhost:8082 . Use following JDBC-string: jdbc:h2:mem:n5DemoDb/jdbc:h2:mem:n5DevDb" + "\n----------------------------------------------------------", env.getProperty("spring.jpa.database"));
}
}
Aggregations