当前位置: 首页>>代码示例>>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;未经允许,请勿转载。