title: How to create an active-mq ExceptionListener?
body: <p>I have a project coded using Spring-hibernate-activeMq</p>
  
  <p>What I would like to know is if I configured activeMq like I explained below, how should I implement the exception listener class of it? I know you don't understand well now but please give a look to my samples below. </p>
  
  <p>Let me know if I implemented exception listener right or not. If not, please give an example how it must be. Thanks in advance.</p>
  
  <p><strong>Application context:</strong> (note that I didn't declare any bean for exception listener except the one the property of connectionFactory)</p>
  
  <pre><code>&lt;bean id="connectionFactory"
        class="org.springframework.jms.connection.CachingConnectionFactory"
        depends-on="broker"&gt;
      &lt;constructor-arg ref="amqConnectionFactory"/&gt;
      &lt;property name="reconnectOnException" value="true"/&gt;
      &lt;property name="exceptionListener" ref="jmsExceptionListener"/&gt; 
      &lt;property name="sessionCacheSize" value="100"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p><strong>Jms exception listener class:</strong> (Note that I am trying to inject ConnectionFactory, I am not sure whether it is possible or not.. And the last thing, please check the constructor arguments of it, I am also not sure of it..)</p>
  
  <pre><code>@Component("jmsExceptionListener")
  public class JMSExceptionListener implements ExceptionListener {
  
  private final static Logger logger = LoggerFactory.getLogger(JMSExceptionListener.class); 
  
  @Autowired
  private CachingConnectionFactory connection;
  
  //    private Connection connection = null;
  
  private ExceptionListener exceptionListener = null; 
  
  public JMSExceptionListener() {
  }
  
  public JMSExceptionListener(CachingConnectionFactory connection, ExceptionListener exceptionListener) {
      super();
      this.connection = connection;
      this.exceptionListener = exceptionListener; 
  }
  
  public void onException(JMSException arg0) {
      logger.error("JMS exception has occured.. ", arg0);
  
      if(connection != null){
          connection.onException(arg0);
      } 
      if (exceptionListener != null) {
          exceptionListener.onException(arg0);
      } 
  } 
  }
  </code></pre>