The Spring JMS Namespace

Version 2.5 of the Spring Framework introduced the JMS XML namespace support, which greatly simplifies the configuration of message-driven POJOs. To add JMS namespace support to your configuration, you would simply specify the JMS schema in the <beans> element of your Spring application context XML file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jms="http://www.springframework.org/schema/jms"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/jms 
http://www.springframework.org/schema/jms/spring-jms-2.5.xsd">

Without the JMS namespace you must define a separate DefaultMessageListenerContainer bean for each message listener you define. In the following example, two message listeners are defined (messageListener1 and messageListener2), which listen on queue1 and queue2, respectively. Notice how you need to define two message listener containers, one for each message listener. This can get quite cumbersome and verbose when using multiple message listeners:

<bean id="messageListener1" class="org.springframework.jms.listener.adapter.MessageListenerAdapter"> <constructor-arg> <bean class="SimpleJMSReceiver1"/> </constructor-arg> <property name="defaultListenerMethod" value="processRequest"/> </bean> <bean id="messageListener2" class="org.springframework.jms.listener.adapter.MessageListenerAdapter"> ...

Get Java Message Service, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.