SpringMVC和Mina集成的配置方法

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<!-- 处理逻辑 -->

<bean id="handler" class="com.cloud.mina.unit_a.strategy.StrategyFactroyHandler" />

<bean id="unitASportsComponent"

        class="com.cloud.mina.component.filter.UnitASportComponent">

        <property name="list">

               <list>

                      <bean class="com.cloud.mina.component.unit_a.sport.SportLoginParser" />

                      <bean class="com.cloud.mina.component.unit_a.sport.No8OneWayParser" />

                      <bean class="com.cloud.mina.component.unit_a.sport.No8TwoWayParser" />

                      <bean class="com.cloud.mina.component.unit_a.sport.No8ThreeWayParser" />

                      <bean class="com.cloud.mina.component.unit_a.sport.SportLogoutParser" />

               </list>

        </property>

</bean>

<!-- 数据包解码器-->

<bean id="codec" class="com.cloud.mina.component.filter.ComponentIOFilter">

        <constructor-arg index="0">

               <bean class="com.cloud.mina.component.filter.MHRootComponent">

                      <property name="list">

                             <list>

                                    <ref bean="unitASportsComponent"></ref>

                                    <ref bean="unitABPComponent"></ref>

                             </list>

                      </property>

               </bean>

        </constructor-arg>

</bean>

<!-- 多线程处理过滤器,为后面的操作开启多线程,一般放在编解码过滤器之后,开始业务逻辑处理 -->

<bean id="executors" class="org.apache.mina.filter.executor.ExecutorFilter" />

<!-- Mina自带日志过滤器 默认级别为debug -->

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

        <property name="messageReceivedLogLevel" ref="info"></property>

        <property name="exceptionCaughtLogLevel" ref="info"></property>

</bean>

<!-- 枚举类型 依赖注入 需要先通过此类进行类型转换 -->

<bean id="info"

        class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">

        <property name="staticField" value="org.apache.mina.filter.logging.LogLevel.INFO" />

</bean>

<bean id="filterChainBuilder"

        class="org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder">

        <property name="filters">

               <map>

                      <entry key="codec" value-ref="codec" />

                      <entry key="logger" value-ref="loggerFilter" />

                      <entry key="executors" value-ref="executors" />

               </map>

        </property>

</bean>

<bean id="defaultLocalAddress" class="java.net.InetSocketAddress">

        <constructor-arg index="0" value="${tcpPort}"></constructor-arg>

</bean>

<!-- session config -->

<bean id="sessionConfig" factory-bean="ioAcceptor" factory-method="getSessionConfig">

        <property name="readerIdleTime" value="40" />

        <property name="minReadBufferSize" value="512" />

        <property name="maxReadBufferSize" value="10240" />

        <!--<property name="readBufferSize" value="20480"/> --><!--<property name="receiveBufferSize" value="5000"/> -->

</bean>

<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor"

        init-method="bind" destroy-method="unbind">

        <!-- 默认启用的线程个数是CPU 的核数+1, -->

        <constructor-arg index="0" value="10"></constructor-arg>

        <property name="defaultLocalAddress" ref="defaultLocalAddress" />

        <property name="handler" ref="handler" />

        <property name="filterChainBuilder" ref="filterChainBuilder" />

</bean>

</beans> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值