I am loading spring application(Using spring 2.5 and cannot upgrade to 3.0) context in stand alone application with spring jms like below
AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
below is my applicationContext.xml
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="destinationName" value="destinationName"/>
<property name="messageListener" ref="jmsMessageListener" />
<property name="exceptionListener" ref="exceptionListener"/>
</bean>
<bean id="jmsMessageListener" class="Listener"/>
<bean id="connectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="hostName" value="${hostName}"/>
<property name="port" value="${port}"/>
<property name="queueManager" value="${queueManager}"/>
<property name="transportType" value="${transportType}"/>
<property name="channel" value="${channel}"/>
</bean>
<bean id = "exceptionListener" class="ExceptionListener">
public class ExceptionListener implements ExceptionListener{
@Override
public void onException(JMSException arg0) {
System.out.println("Exception");
}
}
Now, the problem is by default DefaultMessageListenerContainer tries to recover connection with queue until its successful and i can see the message in log file like below
INFO [jmsContainer-1] org.springframework.jms.listener.DefaultMessageListenerContainer - Could not refresh JMS Connection - retrying in 5000 ms: javax.jms.JMSException: MQJMS2005: failed to create MQQueueManager for 'hostName:queueManager'
But my requirement is that if it fails to connect my application context should stop loading and i can report an error that it is not able to connect and JMSException is thrown.
I tried using exceptionListener for DMLC but its onException message does not get triggered.
I think I can solve this if I somehow override this default behaviour of DMLC or catch the excetion while loading spring application context.
Can anyone suggest how can i acheive any of the above or if there is any other alternative?