title: Apache MINA + Spring - server is not running
body: <p>I have a Spring application and I need to implement very simple communication channel with Apache MINA library. </p>
  
  <p>My Spring application is running but MINA server is not running, in netstat is this port not used.</p>
  
  <p>I followed this tutorial: <a href="http://mina.apache.org/mina-project/userguide/ch17-spring-integration/ch17-spring-integration.html" rel="nofollow">http://mina.apache.org/mina-project/userguide/ch17-spring-integration/ch17-spring-integration.html</a></p>
  
  <p><strong>What am I doing wrong?</strong></p>
  
  <p>This is a handler class:</p>
  
  <pre><code>public class ServerHandler extends IoHandlerAdapter {
  
      @Override
      public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
          cause.printStackTrace();
      }
  
      @Override
      public void messageReceived(IoSession session, Object message) throws Exception {
  
          String str = message.toString();
          if (str.trim().equalsIgnoreCase("quit")) {
              session.close(true);
              return;
          }
          Date date = new Date();
          session.write(date.toString());
          System.out.println("Message written...");
      }
  
      @Override
      public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
          System.out.println("IDLE " + session.getIdleCount(status));
      }
  }
  </code></pre>
  
  <p>And this is a XML configuration from applicationContext.xml</p>
  
  <pre><code>&lt;bean id="trapHandler" class="ServerHandler"&gt;&lt;/bean&gt;
  
      &lt;bean id="snmpCodecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter"&gt;
          &lt;constructor-arg&gt;
              &lt;bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory" /&gt;
          &lt;/constructor-arg&gt;
      &lt;/bean&gt;
  
      &lt;bean id="loggingFilter" class="org.apache.mina.filter.logging.LoggingFilter" /&gt;
  
      &lt;!-- The filter chain. --&gt;
      &lt;bean id="filterChainBuilder" class="org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder"&gt;
          &lt;property name="filters"&gt;
              &lt;map&gt;
                  &lt;entry key="loggingFilter" value-ref="loggingFilter"/&gt;
                  &lt;entry key="codecFilter" value-ref="snmpCodecFilter"/&gt;
              &lt;/map&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"&gt;
          &lt;property name="customEditors"&gt;
              &lt;map&gt;
                  &lt;entry key="java.net.SocketAddress"&gt;
                      &lt;bean class="org.apache.mina.integration.beans.InetSocketAddressEditor" /&gt;
                  &lt;/entry&gt;
              &lt;/map&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- The IoAcceptor which binds to port 161 --&gt;
      &lt;bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioDatagramAcceptor" init-method="bind" destroy-method="unbind"&gt;
          &lt;!--&lt;property name="defaultLocalAddress" value="${interface.ip_address}:${interface.communication.port}" /&gt;--&gt;
          &lt;property name="defaultLocalAddress" value=":6001" /&gt;
          &lt;property name="handler" ref="trapHandler" /&gt;
          &lt;property name="filterChainBuilder" ref="filterChainBuilder" /&gt;
      &lt;/bean&gt;  
  </code></pre>