use of org.springframework.core.env.Environment in project camel by apache.
the class CamelCloudServiceCallConfigurationTest method doTest.
@Test
public void doTest() throws Exception {
Environment env = ctx.getEnvironment();
assertFalse(env.getProperty("camel.cloud.enabled", Boolean.class));
assertFalse(env.getProperty("camel.cloud.service-discovery.enabled", Boolean.class));
assertFalse(env.getProperty("camel.cloud.service-filter.enabled", Boolean.class));
assertTrue(env.getProperty("camel.cloud.service-chooser.enabled", Boolean.class));
assertFalse(env.getProperty("camel.cloud.load-balancer.enabled", Boolean.class));
assertTrue(ctx.getBeansOfType(ServiceDiscovery.class).isEmpty());
assertTrue(ctx.getBeansOfType(ServiceFilter.class).isEmpty());
assertTrue(ctx.getBeansOfType(ServiceChooser.class).isEmpty());
assertTrue(ctx.getBeansOfType(LoadBalancer.class).isEmpty());
}
use of org.springframework.core.env.Environment in project spring-boot-starter-dubbo by teaey.
the class DubboConfigurationApplicationContextInitializer method initialize.
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
Environment env = applicationContext.getEnvironment();
String scan = env.getProperty("spring.dubbo.scan");
if (scan != null) {
AnnotationBean scanner = BeanUtils.instantiate(AnnotationBean.class);
scanner.setPackage(scan);
scanner.setApplicationContext(applicationContext);
applicationContext.addBeanFactoryPostProcessor(scanner);
applicationContext.getBeanFactory().addBeanPostProcessor(scanner);
applicationContext.getBeanFactory().registerSingleton("annotationBean", scanner);
}
}
use of org.springframework.core.env.Environment in project cas by apereo.
the class CasCoreBootstrapStandaloneConfiguration method loadSettingsFromConfigurationSources.
private void loadSettingsFromConfigurationSources(final Environment environment, final Properties props, final File config) {
final List<String> profiles = new ArrayList<>();
profiles.add(configurationPropertiesEnvironmentManager().getApplicationName());
profiles.addAll(Arrays.stream(environment.getActiveProfiles()).collect(Collectors.toList()));
final String propertyNames = profiles.stream().collect(Collectors.joining("|"));
final String regex = String.format("(%s|application)\\.(yml|properties)", propertyNames);
LOGGER.debug("Looking for configuration files at [{}] that match the pattern [{}]", config, regex);
final Collection<File> configFiles = FileUtils.listFiles(config, new RegexFileFilter(regex, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE).stream().sorted(Comparator.comparing(File::getName)).collect(Collectors.toList());
LOGGER.info("Configuration files found at [{}] are [{}]", config, configFiles);
configFiles.forEach(Unchecked.consumer(f -> {
LOGGER.debug("Loading configuration file [{}]", f);
if (f.getName().toLowerCase().endsWith("yml")) {
final Map pp = loadYamlProperties(new FileSystemResource(f));
LOGGER.debug("Found settings [{}] in YAML file [{}]", pp.keySet(), f);
props.putAll(pp);
} else {
final Properties pp = new Properties();
pp.load(new FileReader(f));
LOGGER.debug("Found settings [{}] in file [{}]", pp.keySet(), f);
props.putAll(pp);
}
}));
}
use of org.springframework.core.env.Environment in project camel by apache.
the class CamelTestConfiguration method setApplicationContext.
/**
* Build the URI of the CM Component based on Environmental properties
*/
@Override
public final void setApplicationContext(final ApplicationContext applicationContext) {
super.setApplicationContext(applicationContext);
final Environment env = applicationContext.getEnvironment();
final String host = env.getRequiredProperty("cm.url");
final String productTokenString = env.getRequiredProperty("cm.product-token");
final String sender = env.getRequiredProperty("cm.default-sender");
final StringBuffer cmUri = new StringBuffer("cm-sms:" + host).append("?productToken=").append(productTokenString);
if (sender != null && !sender.isEmpty()) {
cmUri.append("&defaultFrom=").append(sender);
}
// Defaults to false
final Boolean testConnectionOnStartup = Boolean.parseBoolean(env.getProperty("cm.testConnectionOnStartup", "false"));
if (testConnectionOnStartup) {
cmUri.append("&testConnectionOnStartup=").append(testConnectionOnStartup.toString());
}
// Defaults to 8
final Integer defaultMaxNumberOfParts = Integer.parseInt(env.getProperty("defaultMaxNumberOfParts", "8"));
cmUri.append("&defaultMaxNumberOfParts=").append(defaultMaxNumberOfParts.toString());
uri = cmUri.toString();
}
use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class SpringBootJoranConfigurator method addInstanceRules.
@Override
public void addInstanceRules(RuleStore rs) {
super.addInstanceRules(rs);
Environment environment = this.initializationContext.getEnvironment();
rs.addRule(new ElementSelector("configuration/springProperty"), new SpringPropertyAction(environment));
rs.addRule(new ElementSelector("*/springProfile"), new SpringProfileAction(this.initializationContext.getEnvironment()));
rs.addRule(new ElementSelector("*/springProfile/*"), new NOPAction());
}
Aggregations