當前位置: 首頁>>代碼示例>>Java>>正文


Java StaticApplicationContext類代碼示例

本文整理匯總了Java中org.springframework.context.support.StaticApplicationContext的典型用法代碼示例。如果您正苦於以下問題:Java StaticApplicationContext類的具體用法?Java StaticApplicationContext怎麽用?Java StaticApplicationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StaticApplicationContext類屬於org.springframework.context.support包,在下文中一共展示了StaticApplicationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGoodConnection

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void testGoodConnection() throws MqttException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
        null);
    service.setApplicationEventPublisher(applicationContext);
    service.setInboundMessageChannel(inboundMessageChannel);
    service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
        MqttQualityOfService.QOS_0);
    service.getMqttConnectOptions().setCleanSession(true);
    Assert.assertTrue(service.start());
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    Assert.assertEquals(1, clientConnectedCount.get());
    Assert.assertEquals(0, clientDisconnectedCount.get());
    Assert.assertEquals(0, clientLostConnectionCount.get());
    Assert.assertEquals(0, clientFailedConnectionCount.get());
    service.stop();
    service.close();
    applicationContext.close();
}
 
開發者ID:christophersmith,項目名稱:summer-mqtt,代碼行數:25,代碼來源:AutomaticReconnectTest.java

示例2: testWithDefaultStatusPublisher

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void testWithDefaultStatusPublisher() throws MqttException, InterruptedException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getBrokerUri(), BrokerHelper.getClientId(),
        MqttClientConnectionType.PUBSUB, null);
    service.setApplicationEventPublisher(applicationContext);
    service.start();
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    Thread.sleep(1100);
    Assert.assertEquals(0, messageDeliveredCount.get());
    Assert.assertEquals(0, messagePublishedCount.get());
    service.stop();
    service.close();
}
 
開發者ID:christophersmith,項目名稱:summer-mqtt,代碼行數:18,代碼來源:ConnectionStatusTest.java

示例3: testWithNullStatusPublisher

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void testWithNullStatusPublisher() throws MqttException, InterruptedException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getBrokerUri(), BrokerHelper.getClientId(),
        MqttClientConnectionType.PUBSUB, null);
    service.setApplicationEventPublisher(applicationContext);
    service.getMqttClientConfiguration().setMqttClientConnectionStatusPublisher(null);
    service.start();
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    Thread.sleep(1100);
    Assert.assertEquals(0, messageDeliveredCount.get());
    Assert.assertEquals(0, messagePublishedCount.get());
    service.stop();
    service.close();
}
 
開發者ID:christophersmith,項目名稱:summer-mqtt,代碼行數:19,代碼來源:ConnectionStatusTest.java

示例4: testWithCustomStatusPublisher

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void testWithCustomStatusPublisher() throws MqttException, InterruptedException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getBrokerUri(), BrokerHelper.getClientId(),
        MqttClientConnectionType.PUBSUB, null);
    service.setApplicationEventPublisher(applicationContext);
    service.getMqttClientConfiguration().setMqttClientConnectionStatusPublisher(this);
    service.start();
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    Thread.sleep(1100);
    Assert.assertEquals(1, messageDeliveredCount.get());
    Assert.assertEquals(1, messagePublishedCount.get());
    service.stop();
    Thread.sleep(1100);
    Assert.assertEquals(2, messageDeliveredCount.get());
    Assert.assertEquals(2, messagePublishedCount.get());
    service.close();
}
 
開發者ID:christophersmith,項目名稱:summer-mqtt,代碼行數:22,代碼來源:ConnectionStatusTest.java

示例5: taskExecutorByBeanType

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void taskExecutorByBeanType() {
	StaticApplicationContext context = new StaticApplicationContext();

	BeanDefinition processorDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class);
	context.registerBeanDefinition("postProcessor", processorDefinition);

	BeanDefinition executorDefinition = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
	executorDefinition.getPropertyValues().add("threadNamePrefix", "testExecutor");
	context.registerBeanDefinition("myExecutor", executorDefinition);

	BeanDefinition targetDefinition =
			new RootBeanDefinition(AsyncAnnotationBeanPostProcessorTests.TestBean.class);
	context.registerBeanDefinition("target", targetDefinition);

	context.refresh();

	ITestBean testBean = context.getBean("target", ITestBean.class);
	testBean.test();
	testBean.await(3000);
	Thread asyncThread = testBean.getThread();
	assertTrue(asyncThread.getName().startsWith("testExecutor"));
	context.close();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:AsyncAnnotationBeanPostProcessorTests.java

示例6: beanMethodMappings

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void beanMethodMappings() {
	StaticApplicationContext context = new StaticApplicationContext();
	EndpointHandlerMapping mapping = new EndpointHandlerMapping(
			Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint())));
	mapping.setApplicationContext(new StaticApplicationContext());
	mapping.afterPropertiesSet();
	context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping);
	this.endpoint.setApplicationContext(context);
	Map<String, Object> result = this.endpoint.invoke();
	assertThat(result).hasSize(1);
	assertThat(result.keySet().iterator().next().contains("/dump")).isTrue();
	@SuppressWarnings("unchecked")
	Map<String, Object> handler = (Map<String, Object>) result.values().iterator()
			.next();
	assertThat(handler.containsKey("method")).isTrue();
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:18,代碼來源:RequestMappingEndpointTests.java

示例7: classLoading

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
@SuppressWarnings("resource")
public void classLoading() throws Exception {
	StaticApplicationContext context = new StaticApplicationContext();

	GroovyClassLoader gcl = new GroovyClassLoader();
	Class<?> class1 = gcl.parseClass("class TestBean { def myMethod() { \"foo\" } }");
	Class<?> class2 = gcl.parseClass("class TestBean { def myMethod() { \"bar\" } }");

	context.registerBeanDefinition("testBean", new RootBeanDefinition(class1));
	Object testBean1 = context.getBean("testBean");
	Method method1 = class1.getDeclaredMethod("myMethod", new Class<?>[0]);
	Object result1 = ReflectionUtils.invokeMethod(method1, testBean1);
	assertEquals("foo", result1);

	context.removeBeanDefinition("testBean");
	context.registerBeanDefinition("testBean", new RootBeanDefinition(class2));
	Object testBean2 = context.getBean("testBean");
	Method method2 = class2.getDeclaredMethod("myMethod", new Class<?>[0]);
	Object result2 = ReflectionUtils.invokeMethod(method2, testBean2);
	assertEquals("bar", result2);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:GroovyClassLoadingTests.java

示例8: simpleApplicationEventMulticasterWithTaskExecutor

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void simpleApplicationEventMulticasterWithTaskExecutor() {
	@SuppressWarnings("unchecked")
	ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
	ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());

	SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
	smc.setTaskExecutor(new Executor() {
		@Override
		public void execute(Runnable command) {
			command.run();
			command.run();
		}
	});
	smc.addApplicationListener(listener);

	smc.multicastEvent(evt);
	verify(listener, times(2)).onApplicationEvent(evt);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:ApplicationContextEventTests.java

示例9: simpleApplicationEventMulticasterWithException

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void simpleApplicationEventMulticasterWithException() {
	@SuppressWarnings("unchecked")
	ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
	ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());

	SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
	smc.addApplicationListener(listener);

	RuntimeException thrown = new RuntimeException();
	willThrow(thrown).given(listener).onApplicationEvent(evt);
	try {
		smc.multicastEvent(evt);
		fail("Should have thrown RuntimeException");
	}
	catch (RuntimeException ex) {
		assertSame(thrown, ex);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:ApplicationContextEventTests.java

示例10: listenersInApplicationContextWithPayloadEvents

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void listenersInApplicationContextWithPayloadEvents() {
	StaticApplicationContext context = new StaticApplicationContext();
	context.registerBeanDefinition("listener", new RootBeanDefinition(MyPayloadListener.class));
	context.refresh();

	MyPayloadListener listener = context.getBean("listener", MyPayloadListener.class);
	context.publishEvent("event1");
	context.publishEvent("event2");
	context.publishEvent("event3");
	context.publishEvent("event4");
	assertTrue(listener.seenPayloads.contains("event1"));
	assertTrue(listener.seenPayloads.contains("event2"));
	assertTrue(listener.seenPayloads.contains("event3"));
	assertTrue(listener.seenPayloads.contains("event4"));

	AbstractApplicationEventMulticaster multicaster = context.getBean(AbstractApplicationEventMulticaster.class);
	assertEquals(2, multicaster.retrieverCache.size());

	context.close();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:ApplicationContextEventTests.java

示例11: listenersInApplicationContextWithNestedChild

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void listenersInApplicationContextWithNestedChild() {
	StaticApplicationContext context = new StaticApplicationContext();
	RootBeanDefinition nestedChild = new RootBeanDefinition(StaticApplicationContext.class);
	nestedChild.getPropertyValues().add("parent", context);
	nestedChild.setInitMethodName("refresh");
	context.registerBeanDefinition("nestedChild", nestedChild);
	RootBeanDefinition listener1Def = new RootBeanDefinition(MyOrderedListener1.class);
	listener1Def.setDependsOn("nestedChild");
	context.registerBeanDefinition("listener1", listener1Def);
	context.refresh();

	MyOrderedListener1 listener1 = context.getBean("listener1", MyOrderedListener1.class);
	MyEvent event1 = new MyEvent(context);
	context.publishEvent(event1);
	assertTrue(listener1.seenEvents.contains(event1));

	SimpleApplicationEventMulticaster multicaster = context.getBean(
			AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
			SimpleApplicationEventMulticaster.class);
	assertFalse(multicaster.getApplicationListeners().isEmpty());

	context.close();
	assertTrue(multicaster.getApplicationListeners().isEmpty());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:ApplicationContextEventTests.java

示例12: nonSingletonListenerInApplicationContext

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void nonSingletonListenerInApplicationContext() {
	StaticApplicationContext context = new StaticApplicationContext();
	RootBeanDefinition listener = new RootBeanDefinition(MyNonSingletonListener.class);
	listener.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	context.registerBeanDefinition("listener", listener);
	context.refresh();

	MyEvent event1 = new MyEvent(context);
	context.publishEvent(event1);
	MyOtherEvent event2 = new MyOtherEvent(context);
	context.publishEvent(event2);
	MyEvent event3 = new MyEvent(context);
	context.publishEvent(event3);
	MyOtherEvent event4 = new MyOtherEvent(context);
	context.publishEvent(event4);
	assertTrue(MyNonSingletonListener.seenEvents.contains(event1));
	assertTrue(MyNonSingletonListener.seenEvents.contains(event2));
	assertTrue(MyNonSingletonListener.seenEvents.contains(event3));
	assertTrue(MyNonSingletonListener.seenEvents.contains(event4));
	MyNonSingletonListener.seenEvents.clear();

	context.close();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:ApplicationContextEventTests.java

示例13: contextStoppedEvent

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void contextStoppedEvent() {
	StaticApplicationContext context = new StaticApplicationContext();
	context.registerSingleton("lifecycle", LifecycleTestBean.class);
	context.registerSingleton("listener", LifecycleListener.class);
	context.refresh();
	LifecycleTestBean lifecycleBean = (LifecycleTestBean) context.getBean("lifecycle");
	LifecycleListener listener = (LifecycleListener) context.getBean("listener");
	assertFalse(lifecycleBean.isRunning());
	context.start();
	assertTrue(lifecycleBean.isRunning());
	assertEquals(0, listener.getStoppedCount());
	context.stop();
	assertFalse(lifecycleBean.isRunning());
	assertEquals(1, listener.getStoppedCount());
	assertSame(context, listener.getApplicationContext());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:LifecycleEventTests.java

示例14: testQualifiedByParentValue

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void testQualifiedByParentValue() {
	StaticApplicationContext parent = new StaticApplicationContext();
	GenericBeanDefinition parentLarry = new GenericBeanDefinition();
	parentLarry.setBeanClass(Person.class);
	parentLarry.getPropertyValues().add("name", "ParentLarry");
	parentLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "parentLarry"));
	parent.registerBeanDefinition("someLarry", parentLarry);
	GenericBeanDefinition otherLarry = new GenericBeanDefinition();
	otherLarry.setBeanClass(Person.class);
	otherLarry.getPropertyValues().add("name", "OtherLarry");
	otherLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "otherLarry"));
	parent.registerBeanDefinition("someOtherLarry", otherLarry);
	parent.refresh();

	StaticApplicationContext context = new StaticApplicationContext(parent);
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByParentValueTestBean.class);
	context.refresh();
	QualifiedByParentValueTestBean testBean = (QualifiedByParentValueTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("ParentLarry", person.getName());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:QualifierAnnotationTests.java

示例15: testQualifiedByAttributesWithCustomQualifierRegistered

import org.springframework.context.support.StaticApplicationContext; //導入依賴的package包/類
@Test
public void testQualifiedByAttributesWithCustomQualifierRegistered() {
	StaticApplicationContext context = new StaticApplicationContext();
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	QualifierAnnotationAutowireCandidateResolver resolver = (QualifierAnnotationAutowireCandidateResolver)
			context.getDefaultListableBeanFactory().getAutowireCandidateResolver();
	resolver.addQualifierType(MultipleAttributeQualifier.class);
	context.registerSingleton("testBean", MultiQualifierClient.class);
	context.refresh();

	MultiQualifierClient testBean = (MultiQualifierClient) context.getBean("testBean");

	assertNotNull( testBean.factoryTheta);
	assertNotNull( testBean.implTheta);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:QualifierAnnotationTests.java


注:本文中的org.springframework.context.support.StaticApplicationContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。