`
jianFengGong
  • 浏览: 20496 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

MIAN2 Server端与spring的整合

    博客分类:
  • JAVA
阅读更多
项目中遇到要将包含mina2服务端的项目转成web项目,mina也随着web项目启动而启动。以下是部分实现代码:
spring配置文件
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
    <property name="customEditors">
      <map>
        <entry key="java.net.SocketAddress">
          <bean class="org.apache.mina.integration.beans.InetSocketAddressEditor" />
        </entry>
      </map>
    </property>
  </bean>

  <!-- The IoHandler implementation -->
  <bean id="serverHandler" class="com.xxx.server.mina.ServerHandler" />

  <bean id="mdcInjectionFilter" class="org.apache.mina.filter.logging.MdcInjectionFilter">
      <constructor-arg value="remoteAddress"/>
  </bean>

<!-- 引入自定义的CodecFactory-->
<bean id="dcode" class="com.xxx.server.core.MyDecoder" />
<bean id="ecode" class="com.xxx.server.core.MyEncoder" />
  <bean id="codecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
    <constructor-arg>
      <bean class="com.dong.server.core.MyCodecFactory">
      <property name="decoder" ref="dcode"></property>
      <property name="encoder" ref="ecode"></property>
      </bean>
    </constructor-arg>
 
  </bean>

  <bean id="loggingFilter" class="org.apache.mina.filter.logging.LoggingFilter" />

<bean id="filterChainBuilder" class="org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder">
    <property name="filters">
      <map>
        <entry key="codecFilter" value-ref="codecFilter"/>
        <entry key="loggingFilter" value-ref="loggingFilter"/>
      </map>
    </property>
  </bean>

  <!-- The IoAcceptor which binds to port 3005 -->
  <bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor" init-method="bind" destroy-method="unbind">
    <property name="defaultLocalAddress" value=":3005" />
    <property name="handler" ref="serverHandler" />
    <property name="reuseAddress" value="true" />
    <property name="filterChainBuilder" ref="filterChainBuilder" />
  </bean>

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics