本文整理匯總了Java中org.springframework.context.support.GenericApplicationContext.close方法的典型用法代碼示例。如果您正苦於以下問題:Java GenericApplicationContext.close方法的具體用法?Java GenericApplicationContext.close怎麽用?Java GenericApplicationContext.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.context.support.GenericApplicationContext
的用法示例。
在下文中一共展示了GenericApplicationContext.close方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: asyncPrototypeClassListener
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void asyncPrototypeClassListener() throws Exception {
originalThreadName = Thread.currentThread().getName();
listenerCalled = 0;
listenerConstructed = 0;
GenericApplicationContext context = new GenericApplicationContext();
RootBeanDefinition listenerDef = new RootBeanDefinition(AsyncClassListener.class);
listenerDef.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
context.registerBeanDefinition("asyncTest", listenerDef);
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
context.refresh();
context.close();
Thread.sleep(1000);
assertEquals(2, listenerCalled);
assertEquals(2, listenerConstructed);
}
示例2: testNotNullConstraint
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void testNotNullConstraint() {
GenericApplicationContext ac = new GenericApplicationContext();
ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class));
try {
ac.refresh();
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.getRootCause().getMessage().contains("testBean"));
assertTrue(ex.getRootCause().getMessage().contains("invalid"));
}
ac.close();
}
示例3: testSizeConstraint
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void testSizeConstraint() {
GenericApplicationContext ac = new GenericApplicationContext();
ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class);
bd.getPropertyValues().add("testBean", new TestBean());
bd.getPropertyValues().add("stringValue", "s");
ac.registerBeanDefinition("bean", bd);
try {
ac.refresh();
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.getRootCause().getMessage().contains("stringValue"));
assertTrue(ex.getRootCause().getMessage().contains("invalid"));
}
ac.close();
}
示例4: closingChildContextDoesNotCleanUpLoggingSystem
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void closingChildContextDoesNotCleanUpLoggingSystem() {
System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
TestCleanupLoggingSystem.class.getName());
this.initializer.onApplicationEvent(
new ApplicationStartedEvent(this.springApplication, new String[0]));
TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
.getField(this.initializer, "loggingSystem");
assertThat(loggingSystem.cleanedUp).isFalse();
GenericApplicationContext childContext = new GenericApplicationContext();
childContext.setParent(this.context);
this.initializer.onApplicationEvent(new ContextClosedEvent(childContext));
assertThat(loggingSystem.cleanedUp).isFalse();
this.initializer.onApplicationEvent(new ContextClosedEvent(this.context));
assertThat(loggingSystem.cleanedUp).isTrue();
childContext.close();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:LoggingApplicationListenerTests.java
示例5: testRegistrationWithParentContext
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void testRegistrationWithParentContext() throws Exception {
this.context = new GenericApplicationContext();
this.context.registerBeanDefinition("endpointMbeanExporter",
new RootBeanDefinition(EndpointMBeanExporter.class));
this.context.registerBeanDefinition("endpoint1",
new RootBeanDefinition(TestEndpoint.class));
GenericApplicationContext parent = new GenericApplicationContext();
this.context.setParent(parent);
parent.refresh();
this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertThat(mbeanExporter.getServer()
.getMBeanInfo(getObjectName("endpoint1", this.context))).isNotNull();
parent.close();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:EndpointMBeanExporterTests.java
示例6: asyncClassListener
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void asyncClassListener() throws Exception {
originalThreadName = Thread.currentThread().getName();
listenerCalled = 0;
listenerConstructed = 0;
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncClassListener.class));
context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
context.refresh();
context.close();
Thread.sleep(1000);
assertEquals(2, listenerCalled);
assertEquals(1, listenerConstructed);
}
示例7: testDefaultInitAndDestroyMethodsNotDefined
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void testDefaultInitAndDestroyMethodsNotDefined() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertFalse("bean should not have been initialized", bean.isInitialized());
context.close();
assertFalse("bean should not have been destroyed", bean.isDestroyed());
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:ComponentScanParserBeanDefinitionDefaultsTests.java
示例8: testDefaultInitAndDestroyMethodsDefined
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void testDefaultInitAndDestroyMethodsDefined() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultInitAndDestroyMethodsTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertTrue("bean should have been initialized", bean.isInitialized());
context.close();
assertTrue("bean should have been destroyed", bean.isDestroyed());
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:ComponentScanParserBeanDefinitionDefaultsTests.java
示例9: testDefaultNonExistingInitAndDestroyMethodsDefined
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void testDefaultNonExistingInitAndDestroyMethodsDefined() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultNonExistingInitAndDestroyMethodsTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertFalse("bean should not have been initialized", bean.isInitialized());
context.close();
assertFalse("bean should not have been destroyed", bean.isDestroyed());
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:ComponentScanParserBeanDefinitionDefaultsTests.java
示例10: testPostConstructAndPreDestroyWithApplicationContextAndPostProcessor
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void testPostConstructAndPreDestroyWithApplicationContextAndPostProcessor() {
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition("bpp1", new RootBeanDefinition(InitDestroyBeanPostProcessor.class));
ctx.registerBeanDefinition("bpp2", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
ctx.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));
ctx.refresh();
AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) ctx.getBean("annotatedBean");
assertTrue(bean.initCalled);
ctx.close();
assertTrue(bean.destroyCalled);
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:CommonAnnotationBeanPostProcessorTests.java
示例11: beanPostProcessorPublishesEvents
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void beanPostProcessorPublishesEvents() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("listener", new RootBeanDefinition(BeanThatListens.class));
context.registerBeanDefinition("messageSource", new RootBeanDefinition(StaticMessageSource.class));
context.registerBeanDefinition("postProcessor", new RootBeanDefinition(EventPublishingBeanPostProcessor.class));
context.refresh();
context.publishEvent(new MyEvent(this));
BeanThatListens listener = context.getBean(BeanThatListens.class);
assertEquals(4, listener.getEventCount());
context.close();
}
示例12: testNotNullConstraintSatisfied
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void testNotNullConstraintSatisfied() {
GenericApplicationContext ac = new GenericApplicationContext();
ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class);
bd.getPropertyValues().add("testBean", new TestBean());
ac.registerBeanDefinition("bean", bd);
ac.refresh();
ac.close();
}
示例13: testNotNullConstraintAfterInitialization
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void testNotNullConstraintAfterInitialization() {
GenericApplicationContext ac = new GenericApplicationContext();
RootBeanDefinition bvpp = new RootBeanDefinition(BeanValidationPostProcessor.class);
bvpp.getPropertyValues().add("afterInitialization", true);
ac.registerBeanDefinition("bvpp", bvpp);
ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
ac.registerBeanDefinition("bean", new RootBeanDefinition(AfterInitConstraintBean.class));
ac.refresh();
ac.close();
}
示例14: testSizeConstraintSatisfied
import org.springframework.context.support.GenericApplicationContext; //導入方法依賴的package包/類
@Test
public void testSizeConstraintSatisfied() {
GenericApplicationContext ac = new GenericApplicationContext();
ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class);
bd.getPropertyValues().add("testBean", new TestBean());
bd.getPropertyValues().add("stringValue", "ss");
ac.registerBeanDefinition("bean", bd);
ac.refresh();
ac.close();
}