use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class OnEnabledResourceChainCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment();
boolean fixed = getEnabledProperty(environment, "strategy.fixed.", false);
boolean content = getEnabledProperty(environment, "strategy.content.", false);
Boolean chain = getEnabledProperty(environment, "", null);
Boolean match = ResourceProperties.Chain.getEnabled(fixed, content, chain);
ConditionMessage.Builder message = ConditionMessage.forCondition(ConditionalOnEnabledResourceChain.class);
if (match == null) {
if (ClassUtils.isPresent(WEBJAR_ASSET_LOCATOR, getClass().getClassLoader())) {
return ConditionOutcome.match(message.found("class").items(WEBJAR_ASSET_LOCATOR));
}
return ConditionOutcome.noMatch(message.didNotFind("class").items(WEBJAR_ASSET_LOCATOR));
}
if (match) {
return ConditionOutcome.match(message.because("enabled"));
}
return ConditionOutcome.noMatch(message.because("disabled"));
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-framework by spring-projects.
the class NestedBeansElementTests method getBean_withActiveProfile.
@Test
public void getBean_withActiveProfile() {
ConfigurableEnvironment env = new StandardEnvironment();
env.setActiveProfiles("dev");
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
reader.setEnvironment(env);
reader.loadBeanDefinitions(XML);
// should not throw NSBDE
bf.getBean("devOnlyBean");
Object foo = bf.getBean("foo");
assertThat(foo, instanceOf(Integer.class));
bf.getBean("devOnlyBean");
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-framework by spring-projects.
the class ProfileXmlBeanDefinitionTests method testDefaultAndNonDefaultProfile.
@Test
public void testDefaultAndNonDefaultProfile() {
assertThat(beanFactoryFor(DEFAULT_ELIGIBLE_XML, NONE_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(DEFAULT_ELIGIBLE_XML, "other"), not(containsTargetBean()));
{
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
ConfigurableEnvironment env = new StandardEnvironment();
env.setActiveProfiles(DEV_ACTIVE);
env.setDefaultProfiles("default");
reader.setEnvironment(env);
reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_AND_DEV_ELIGIBLE_XML, getClass()));
assertThat(beanFactory, containsTargetBean());
}
{
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
ConfigurableEnvironment env = new StandardEnvironment();
// env.setActiveProfiles(DEV_ACTIVE);
env.setDefaultProfiles("default");
reader.setEnvironment(env);
reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_AND_DEV_ELIGIBLE_XML, getClass()));
assertThat(beanFactory, containsTargetBean());
}
{
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
ConfigurableEnvironment env = new StandardEnvironment();
// env.setActiveProfiles(DEV_ACTIVE);
//env.setDefaultProfiles("default");
reader.setEnvironment(env);
reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_AND_DEV_ELIGIBLE_XML, getClass()));
assertThat(beanFactory, containsTargetBean());
}
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class DevToolsHomePropertiesPostProcessorTests method loadsHomeProperties.
@Test
public void loadsHomeProperties() throws Exception {
Properties properties = new Properties();
properties.put("abc", "def");
OutputStream out = new FileOutputStream(new File(this.home, ".spring-boot-devtools.properties"));
properties.store(out, null);
out.close();
ConfigurableEnvironment environment = new MockEnvironment();
MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor();
postProcessor.postProcessEnvironment(environment, null);
assertThat(environment.getProperty("abc")).isEqualTo("def");
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method customDefaultProfileAndActiveFromFile.
@Test
public void customDefaultProfileAndActiveFromFile() throws Exception {
// gh-5998
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run("--spring.config.name=customprofile", "--spring.profiles.default=customdefault");
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment.containsProperty("customprofile")).isTrue();
assertThat(environment.containsProperty("customprofile-specific")).isTrue();
assertThat(environment.containsProperty("customprofile-customdefault")).isTrue();
assertThat(environment.acceptsProfiles("customdefault")).isTrue();
}
Aggregations