title: spring integration with activemq,pool not open
body: <p>I used Spring 4.3.14 to integrate activemq 5.1.45. The message queue can be used normally when the service is started, but after running for a while, the console starts to appear </p>
  
  <pre><code>WARN DefaultMessageListenerContainer - Setup of JMS message listener invoker failed for destination 'queue://queue '-Try to recover. Cause: Connection closed'
  </code></pre>
  
  <p>warning, but the message queue is still available. After a few hours, it will not work. When trying to send a message to the queue, the console reports </p>
  
  <pre><code>    java.lang.IllegalStateException: Pool not open; nested exception is javax.jms.IllegalStateException: java.lang.IllegalStateException: Pool not open
  org.springframework.jms.IllegalStateException: java.lang.IllegalStateException: Pool not open; nested exception is javax.jms.IllegalStateException: java.lang.IllegalStateException: Pool not open
      at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:279)
      at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:169)
      at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:487)
      at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:559)
      at com.xxx.core.service.impl.ProducerServiceImpl.sendMessage(ProducerServiceImpl.java:32)
      at com.xxx.core.service.impl.MQProducerServiceImpl.sendMessage(MQProducerServiceImpl.java:34)
      at com.xxx.web.controller.xxx.XxxController.reward(XxxController.java:563)
      at sun.reflect.GeneratedMethodAccessor822.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45005)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at com.xxx.platform.common.log.filter.RequestDigestAndLog4jMDCInitFilter.doFilterInternal(RequestDigestAndLog4jMDCInitFilter.java:128)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
      at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:110)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:40002)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: javax.jms.IllegalStateException: java.lang.IllegalStateException: Pool not open
      at org.apache.activemq.jms.pool.ConnectionPool.createSession(ConnectionPool.java:162)
      at org.apache.activemq.jms.pool.PooledConnection.createSession(PooledConnection.java:167)
      at sun.reflect.GeneratedMethodAccessor1072.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45005)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.springframework.jms.connection.SingleConnectionFactory$SharedConnectionInvocationHandler.invoke(SingleConnectionFactory.java:620)
      at com.sun.proxy.$Proxy51.createSession(Unknown Source)
      at org.springframework.jms.support.JmsAccessor.createSession(JmsAccessor.java:192)
      at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:475)
      ... 49 more
  Caused by: java.lang.IllegalStateException: Pool not open
      at org.apache.commons.pool2.impl.BaseGenericObjectPool.assertOpen(BaseGenericObjectPool.java:605)
      at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:332)
      at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:276)
      at org.apache.activemq.jms.pool.ConnectionPool.createSession(ConnectionPool.java:144)
      ... 57 more
  </code></pre>
  
  <p>In debug mode can see that "org.springframework.jms.connection.SingleConnectionFactory.connection.pool" is null.</p>
  
  <p>My Spring configuration is</p>
  
  <pre><code>&lt;bean id="targetConnectionFactory"
      class="org.apache.activemq.ActiveMQConnectionFactory"&gt;
      &lt;property name="brokerURL" value="tcp://localhost:61616" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="pooledConnectionFactory"
      class="org.apache.activemq.pool.PooledConnectionFactory"&gt;
      &lt;property name="connectionFactory"
          ref="targetConnectionFactory" /&gt;
      &lt;property name="maxConnections" value="30" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="connectionFactory"
      class="org.springframework.jms.connection.SingleConnectionFactory"&gt;
      &lt;property name="targetConnectionFactory"
          ref="pooledConnectionFactory" /&gt;
      &lt;property name="reconnectOnException" value="true" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jmsTemplate"
      class="org.springframework.jms.core.JmsTemplate"&gt;
      &lt;property name="connectionFactory" ref="connectionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="queueDestination"
      class="org.apache.activemq.command.ActiveMQQueue"&gt;
      &lt;constructor-arg&gt;
          &lt;value&gt;queue&lt;/value&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  
  &lt;bean id="topicDestination"
      class="org.apache.activemq.command.ActiveMQTopic"&gt;
      &lt;constructor-arg value="topic" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="consumerMessageListener"
      class="com.xxx.activmq.ConsumerMessageListener" /&gt;
  &lt;bean id="jmsContainer"
      class="org.springframework.jms.listener.DefaultMessageListenerContainer"&gt;
      &lt;property name="connectionFactory" ref="connectionFactory" /&gt;
      &lt;property name="destination" ref="queueDestination" /&gt;
      &lt;property name="messageListener"
          ref="consumerMessageListener" /&gt;
  &lt;/bean&gt;
  </code></pre>