@Test public void testJmsTemplateByConsumer(){ ApplicationContext ioc = new ClassPathXmlApplicationContext("applicationContext.xml"); JmsTemplate jmsTemplate = (JmsTemplate) ioc.getBean("jmsTemplate"); String returnValue = (String) jmsTemplate.receiveAndConvert(); System.out.println(returnValue); }
上面是queue,如果想要换成topic,直接在ioc配置文件切换就行。