Apache mina 与Spring整合设计

<?xmlversion="1.0"encoding="UTF-8"?>

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

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

xmlns:p="http://www.springframework.org/schema/p"

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

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

<beanid="socketHandler"class="com.test.core.mina.SocketHandler"/><!--服务器端数据处理器1-->

<!--服务器端数据编码1-->

<beanid="messEncode"class="com.test.core.mina.MessEncode"

p:messageUtil-ref="messageUtil"

/>

<!--服务器端数据解码1-->

<beanid="messDecode"class="com.test.core.mina.MessDecode"

p:messageUtil-ref="messageUtil"

/>

<!--服务器端过滤器1-->

<beanid="MessCodecFilter"class="org.apache.mina.filter.codec.ProtocolCodecFilter">

<constructor-arg>

<beanclass="com.test.core.mina.MessProtocolCodecFactory"

p:messEncode-ref="messEncode"p:messDecode-ref="messDecode"

/>

</constructor-arg>

</bean>

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

<!--服务器端过滤器链1-->

<beanid="filterChainBuilder"

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

<propertyname="filters">

<map>

<entrykey="loggingFilter"value-ref="loggingFilter"/>

<entrykey="codecFilter"value-ref="MessCodecFilter"/>

</map>

</property>

</bean>

<!--定义属性编辑器,在这里用处不大,当某一个类声明啦java.net.InetSocketAddress成员变量时可以用配置文件赋值-->

<beanclass="org.springframework.beans.factory.config.CustomEditorConfigurer">

<propertyname="customEditors">

<map>

<entrykey="java.net.InetSocketAddress"><!--属性类型-->

<!--mina提供的自定义属性编辑器-->

<beanclass="org.apache.mina.integration.beans.InetSocketAddressEditor"/>

</entry>

</map>

</property>

</bean>

<!--

##########################################################################

为了更好的进行开发维护,MINA框架中的IP和端口放到xxx.properties文件中

进行维护。

##########################################################################

-->

<!--服务器1-->

<beanid="nioAcceptor"class="org.apache.mina.transport.socket.nio.NioSocketAcceptor"

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

<propertyname="defaultLocalAddress"value="127.0.0.1:8000"/>

<propertyname="handler"ref="socketHandler"/>

<propertyname="filterChainBuilder"ref="filterChainBuilder"/>

</bean>

</beans>

相关推荐