Not sure this is the best place for it but here it is. The formatting isn't preserved 
1.1. Factory Classes
A collection of factory classes are provided to create instances of a JMS Connection, Session, MessageProducer, and MessageConsumer and expose them inside an application context. This can be an effective means for configuring a JMS based application.
The factories are for use only with JMS 1.1 providers. The JmsConnectionFactoryBean will return a singleton/non-prototype connection and requires a reference to a ConnectionFactory. Setting the ClientID property of the connection should only be done if it is not configured in a client-specific ConnectionFactory implementation. The JmsSessionFactoryBean will return a singleton/non-prototype session and requires a reference to a Connection. The JmsProducerFactoryBean creates a new prototype instance of MessageProducer. You can specify all the various QOS properties, disable message ID and timestamp creation, and destination. The JmsConsumerFactoryBean creates a new prototype instance of a MessageConsumer and requires a reference to a session and destination. You can also create a durable subscriber to a topic.
The following application context listing shows how you can use the factory classes to send a message.
Code:
<beans>
<bean id="jmsSendExample" class="example.jms.JmsSendExample">
<property name="session"><ref bean="jmsSession"/></property>
<property name="producer"><ref bean="jmsProducer"/></property>
</bean>
<bean id="jmsProducer" class="org.springframework.jms.JmsProducerFactoryBean">
<property name="session"><ref bean="jmsSession"/></property>
<property name="destination"><ref bean="queue"/></property>
<property name="priority"><value>6</value></property>
</bean>
<bean id="queue" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>testQueueJndi</value></property>
</bean>
<bean id="jmsSession" class="org.springframework.jms.JmsSessionFactoryBean">
<property name="transacted"><value>false</value></property>
<property name="connection"><ref bean="jmsConnection"/></property>
</bean>
<bean id="jmsConnection" class="org.springframework.jms.JmsConnectionFactoryBean">
<property name="connectionFactory"><ref bean="jmsConnFactory"/></property>
</bean>
<bean id="jmsConnFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>QueueConnectionFactory</value></property>
</bean>
</beans>
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
public class JmsSendExample
{
private Session session;
private MessageProducer producer;
public void setProducer(MessageProducer producer)
{
this.producer = producer;
}
public void setSession(Session s)
{
session = s;
}
public void sendMessage() throws JMSException
{
Message m = session.createTextMessage("Hello World!");
producer.send(m);
System.out.println("Sent message = " + m);
}
public static void main(String[] args) throws JMSException
{
String ctxFile = "/example/jms/appContext.xml";
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(ctxFile);
JmsSendExample sendExample = (JmsSendExample) ctx.getBean("jmsSendExample");
sendExample.sendMessage();
ctx.getBeanFactory().destroySingletons();
}
}
Similarly, to receive a message add the following to the application context
Code:
<bean id="jmsConsumer" class="org.springframework.jms.JmsConsumerFactoryBean">
<property name="session"><ref bean="jmsSession"/></property>
<property name="destination"><ref bean="queue"/></property>
<property name="messageListener"><ref bean="msgListener"/></property>
</bean>
<bean id="msgListener" class="example.jms.JmsMsgListener">
</bean>
The java code to receive the message is then
Code:
public static void main(String[] args) throws Exception
{
String ctxFile = "/example/jms/appContext.xml";
ApplicationContext ctx = new ClassPathXmlApplicationContext(ctxFile);
Connection c = (Connection) ctx.getBean("jmsConnection");
c.start();
System.out.println("Listening for messages");
Thread.sleep(100000);
}
A durable consumber on for a topic is specified by setting the isDurableSubscriber property to true. Durable Subscriptions only apply to the publish-subscribe messaging domain and you must provide a durable identity for the subscriber.
The full lifecycle management of starting and stopping the JMS Connection after all beans have been initialized is left to the application code. You should avoid initialization methods on beans that may start the JMS connection since messages can be delivered before the BeanFactory has finished processing all the objects. Some helper classes for this case are in the sandbox under the package org.springframework.service but the depends-on attribute in a bean declaration can be leverged as well.