@Test public void messageDrivenAdapterWithMessageConverter() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsInboundWithMessageConverter.xml", this.getClass()); PollableChannel output = (PollableChannel) context.getBean("output2"); Message<?> message = output.receive(timeoutOnReceive); assertNotNull("message should not be null", message); assertEquals("converted-test", message.getPayload()); context.stop(); }
@Test public void adapterWithMessageSelector() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsInboundWithMessageSelector.xml", this.getClass()); PollableChannel output = (PollableChannel) context.getBean("output1"); Message<?> message = output.receive(timeoutOnReceive); assertNotNull("message should not be null", message); assertEquals("test [with selector: TestProperty = 'foo']", message.getPayload()); context.stop(); }
@Test public void adapterWithConnectionFactoryAndDestinationName() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "jmsInboundWithConnectionFactoryAndDestinationName.xml", this.getClass()); PollableChannel output = (PollableChannel) context.getBean("output"); Message<?> message = output.receive(timeoutOnReceive); assertNotNull("message should not be null", message); assertEquals("polling-test", message.getPayload()); context.stop(); }
@Test public void adapterWithoutJmsTemplateAndAcknowlegeMode() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsInboundWithJmsTemplate.xml", this.getClass()); JmsTemplate jmsTemplate = TestUtils.getPropertyValue( context.getBean("inboundAdapterWithoutJmsTemplate"), "source.jmsTemplate", JmsTemplate.class); assertEquals(0, jmsTemplate.getSessionAcknowledgeMode()); context.stop(); }
@Test public void adapterWithHeaderMapper() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsInboundWithHeaderMapper.xml", this.getClass()); PollableChannel output = (PollableChannel) context.getBean("output"); Message<?> message = output.receive(timeoutOnReceive); assertNotNull("message should not be null", message); assertEquals("polling-test", message.getPayload()); assertEquals("foo", message.getHeaders().get("testProperty")); assertEquals(new Integer(123), message.getHeaders().get("testAttribute")); context.stop(); }
@Override public void stop() { try { if (context != null) { context.stop(); context.close(); context = null; } log.info(LOGNAME, "{} stopped success."); } catch (Throwable e) { log.error("{} stopped error:{}", e, LOGNAME); } }
@Test public void testGatewayWithMessageConverter() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsGatewayWithMessageConverter.xml", this.getClass()); PollableChannel channel = (PollableChannel) context.getBean("requestChannel"); JmsMessageDrivenEndpoint gateway = (JmsMessageDrivenEndpoint) context.getBean("jmsGateway"); assertEquals(JmsMessageDrivenEndpoint.class, gateway.getClass()); context.start(); Message<?> message = channel.receive(3000); assertNotNull("message should not be null", message); assertEquals("converted-test-message", message.getPayload()); context.stop(); }
public void demoSpring() { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"springExample.xml"}); LifeTest lt = context.getBean("lifeTest", LifeTest.class); LifeTest2 lt2 = context.getBean("lifeTest2", LifeTest2.class); // Надо привести к типу ClassPathXmlApplicationContext для использования destroy ((ClassPathXmlApplicationContext) context).start(); ((ClassPathXmlApplicationContext) context).stop(); // ((ClassPathXmlApplicationContext)context).close(); ((ClassPathXmlApplicationContext) context).refresh(); }
public static void main(String[] args) { System.out.println("Start spring container"); System.out.println("======================="); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); System.out.println("Stop spring container"); System.out.println("======================="); context.stop(); context.close(); context.destroy(); System.out.println("Start spring container"); System.out.println("======================="); context = new ClassPathXmlApplicationContext("beans.xml"); context.close(); context.destroy(); }
private static void start() { System.out.println(System.getProperty("dubbo.properties.file")); ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("classpath*:/META-INF/spring/*.xml"); classPathXmlApplicationContext.start(); running = true; synchronized (Main.class) { while (running) { try { Main.class.wait(); } catch (Throwable e) { } } classPathXmlApplicationContext.stop(); } }
@Test public void adapterWithJmsTemplate() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsInboundWithJmsTemplate.xml", this.getClass()); PollableChannel output = (PollableChannel) context.getBean("output"); Message<?> message = output.receive(timeoutOnReceive); MessageHistory history = MessageHistory.read(message); assertNotNull(history); Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "inboundAdapter", 0); assertNotNull(componentHistoryRecord); assertEquals("jms:inbound-channel-adapter", componentHistoryRecord.get("type")); assertNotNull("message should not be null", message); assertEquals("polling-test", message.getPayload()); context.stop(); }
@Test public void testGatewayWithConnectionFactoryAndDestination() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "jmsGatewayWithConnectionFactoryAndDestination.xml", this.getClass()); PollableChannel channel = (PollableChannel) context.getBean("requestChannel"); JmsMessageDrivenEndpoint gateway = (JmsMessageDrivenEndpoint) context.getBean("jmsGateway"); assertEquals(JmsMessageDrivenEndpoint.class, gateway.getClass()); context.start(); Message<?> message = channel.receive(3000); MessageHistory history = MessageHistory.read(message); assertNotNull(history); Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "jmsGateway", 0); assertNotNull(componentHistoryRecord); assertEquals("jms:inbound-gateway", componentHistoryRecord.get("type")); assertNotNull("message should not be null", message); assertEquals("message-driven-test", message.getPayload()); context.stop(); }
@After public void tearDown() { if (applicationContext != null) { applicationContext.stop(); } }