<context:annotation-config/>
<bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory"
p:brokerURL="tcp://localhost:61616" />
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<constructor-arg name="connectionFactory" ref="connectionFactory"/>
<property name="defaultDestinationName" value="prospring3"/>
</bean>
<context:component-scan
base-package="com.apress.prospring3.ch16.jms.sender"/>
</beans>
As shown in Listing 16-18, the connectionFactory bean is defined as usual. In addition, an instance
of JmsTemplate is declared, with the connectionFactory as the constructor argument, and the
defaultDestinationName is set to the prospring3 queue.
Listing 16-19 shows the main testing program for sending messages.
Listing 16-19. Test Sending Messages
package com.apress.prospring3.ch16.jms;
import org.springframework.context.support.GenericXmlApplicationContext;
import com.apress.prospring3.ch16.jms.sender.MessageSender;
public class JmsSenderSample {
public static void main(String[] args) {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load("classpath:jms-sender-app-context.xml");
ctx.refresh();
// Send message
MessageSender messageSender = ctx.getBean("messageSender",
MessageSender.class);
messageSender.sendMessage("Clarence testing JMS message");
}
}
Search WWH :