ifishTools/src/main/resources/mina.xml

72 lines
2.9 KiB
XML

<?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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 注册识别注解 -->
<context:annotation-config />
<!-- 导入外部的properties文件-->
<context:property-placeholder location="classpath*:property.properties" ignore-unresolvable="true"/>
<!-- 消息处理类 -->
<bean id="someServer" class="com.ifish.socket.SomeServer">
<constructor-arg index="0">
<value>${ifish.factory}</value>
</constructor-arg>
<constructor-arg index="1">
<value>${ifish.replay}</value>
</constructor-arg>
</bean>
<!-- 自定义的serverHandler -->
<bean id="serverHandler" class="com.ifish.socket.MinaServerHandler"></bean>
<!-- 指定服务端地址和端口 -->
<bean id="address" class="com.ifish.socket.util.MyInetSocketAddress">
<constructor-arg index="0">
<value>${ifish.port}</value>
</constructor-arg>
</bean>
<!-- 编码filter -->
<bean id="codecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg>
<!-- 自定义的字符编码类 -->
<bean class="com.ifish.socket.codeFactory.ServerCodecFactory"></bean>
</constructor-arg>
</bean>
<!-- 日志filter -->
<bean id="loggingFilter" class="org.apache.mina.filter.logging.LoggingFilter"></bean>
<!-- 过滤器链 -->
<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>
<!-- SessionConfig 通过工厂方法注入 -->
<bean id="sessionConfig" factory-bean="ioAcceptor" factory-method="getSessionConfig">
<property name="bothIdleTime" value="20" />
<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">
<property name="defaultLocalAddress" value="#{address.socketAddress}" />
<property name="handler" ref="serverHandler" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
<property name="reuseAddress" value="true" />
</bean>
</beans>