Mina框架与Spring整合配置文件-阿里云开发者社区

开发者社区> 开发与运维> 正文

Mina框架与Spring整合配置文件

简介:

米娜框架与春天配置整合性文件

米娜框架与春天的整合其实很简单,主要是要弄清楚要注入的属性的名称,进而选择合适的注入方法。

<?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.mina.handler.StrategyFactoryHandler“/>

<! - 累加数据包解码器:解断丢包,粘包问题 - >
<bean id =“codec”class =“org.apache.mina.filter.codec.ProtocolCodecFilter”>
<constructor-arg>
< bean class =“com.mina.codec.MyCodecFcatory”>
<constructor-arg index =“0”>
<bean class =“com.mina.codec.MyEncoder”> </ bean>
</ constructor-arg>
<constructor- arg index =“1”>
<bean class =“com.mina.codec.MyDecoder”>
</ bean>
</ constructor-arg>

</ 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 =“10”/>
<property name =“minReadBufferSize”value =“512”/>
<property name =“maxReadBufferSize”value =“10240”/>
</ 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>

地址原文http://www.bieryun.com/1800.html

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章