Java Code Examples for org.springframework.context.support.GenericApplicationContext#setEnvironment()

The following examples show how to use org.springframework.context.support.GenericApplicationContext#setEnvironment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnvironmentSystemIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void genericApplicationContext_customEnv() {
	GenericApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
	ctx.setEnvironment(prodEnv);
	ctx.refresh();

	assertHasEnvironment(ctx, prodEnv);
	assertEnvironmentBeanRegistered(ctx);
	assertEnvironmentAwareInvoked(ctx, prodEnv);
}
 
Example 2
Source File: EnvironmentSystemIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void xmlBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(XML_PATH);
	ctx.refresh();
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 3
Source File: EnvironmentSystemIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	new AnnotatedBeanDefinitionReader(ctx).register(Config.class);
	ctx.refresh();
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 4
Source File: EnvironmentSystemIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedConfigClasses() {
	// it's actually ConfigurationClassPostProcessor's Environment that gets the job done here.
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
	scanner.scan("org.springframework.core.env.scan1");
	ctx.refresh();
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 5
Source File: EnvironmentSystemIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedComponents() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
	scanner.scan("org.springframework.core.env.scan2");
	ctx.refresh();
	assertThat(scanner.getEnvironment(), is((Environment)ctx.getEnvironment()));
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 6
Source File: EnvironmentSystemIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void genericApplicationContext_customEnv() {
	GenericApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
	ctx.setEnvironment(prodEnv);
	ctx.refresh();

	assertHasEnvironment(ctx, prodEnv);
	assertEnvironmentBeanRegistered(ctx);
	assertEnvironmentAwareInvoked(ctx, prodEnv);
}
 
Example 7
Source File: EnvironmentSystemIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void xmlBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(XML_PATH);
	ctx.refresh();
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 8
Source File: EnvironmentSystemIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	new AnnotatedBeanDefinitionReader(ctx).register(Config.class);
	ctx.refresh();
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 9
Source File: EnvironmentSystemIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedConfigClasses() {
	// it's actually ConfigurationClassPostProcessor's Environment that gets the job done here.
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
	scanner.scan("org.springframework.core.env.scan1");
	ctx.refresh();
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 10
Source File: EnvironmentSystemIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedComponents() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
	scanner.scan("org.springframework.core.env.scan2");
	ctx.refresh();
	assertThat(scanner.getEnvironment(), is((Environment)ctx.getEnvironment()));
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 11
Source File: EnvironmentSystemIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void genericApplicationContext_customEnv() {
	GenericApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
	ctx.setEnvironment(prodEnv);
	ctx.refresh();

	assertHasEnvironment(ctx, prodEnv);
	assertEnvironmentBeanRegistered(ctx);
	assertEnvironmentAwareInvoked(ctx, prodEnv);
}
 
Example 12
Source File: EnvironmentSystemIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void xmlBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(XML_PATH);
	ctx.refresh();
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 13
Source File: EnvironmentSystemIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	new AnnotatedBeanDefinitionReader(ctx).register(Config.class);
	ctx.refresh();
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 14
Source File: EnvironmentSystemIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedConfigClasses() {
	// it's actually ConfigurationClassPostProcessor's Environment that gets the job done here.
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
	scanner.scan("org.springframework.core.env.scan1");
	ctx.refresh();
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
Example 15
Source File: EnvironmentSystemIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedComponents() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
	scanner.scan("org.springframework.core.env.scan2");
	ctx.refresh();
	assertThat(scanner.getEnvironment(), is((Environment)ctx.getEnvironment()));
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}