Apache Mina 与Spring 整合问题

时间:2022-04-26 19:58:03
刚接触Mina

按官网上说的配置了 8888端口。。。启动了Jetty也没有报错
netstat -ano看了一下
 UDP    0.0.0.0:8888           *:*                                    4532

为什么是0.0.0.0??? telnet 也不通???
下面是我的配置文件

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">


<!-- Mina Server 配置-->
<bean id="trapHandler" class="org.g4studio.mina.server.ServerHandler" />

<bean id="snmpCodecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg>
<bean class="org.g4studio.mina.textcode.MyTextLineCodecFactory" />
</constructor-arg>
</bean>

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

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

<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 IoAcceptor which binds to port 161 -->
<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioDatagramAcceptor" init-method="bind" destroy-method="unbind">
<property name="defaultLocalAddress" value=":8888" />
<property name="handler" ref="trapHandler" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
</bean>
</beans>

6 个解决方案

#1


telnet是TCP传输的协议, 你配置的是UDP    0.0.0.0:8888  *:*  4532,是UDP

#2


对呀,在哪配置的?

#3


下面是我的配置 给你参考一下 

<?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:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" default-autowire="byName">                 


<!-- 配置IP -->
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.net.InetSocketAddress">
<bean class="org.apache.mina.integration.beans.InetSocketAddressEditor" />
</entry>
</map>
</property>
</bean>

<!-- 配置service  -->
<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor" 
init-method="bind" destroy-method="unbind" >
<property name="defaultLocalAddress" value=":6007" />
<property name="handler" ref="testServiceHandler" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
<!-- <bean  class="org.apache.mina.transport.socket.DefaultSocketSessionConfig" >
<property name="bothIdleTime" value="10"></property>
<property name="readBufferSize" value="2048"></property>
</bean> -->

</bean>


<!-- 配置业务处理类 -->
<bean id="testServiceHandler" class="com.mina.test.service.TestServiceHandler">
</bean>

<!-- 配置数据库操作工具类 
<bean id="du" class="com.mina.test.util.DaoUtil">
</bean>-->

<!-- 配置解码器 -->
<bean id="codec" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg>
<bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory" />
</constructor-arg>
</bean>

<!-- 配置日志拦截器 -->
<bean id="logger" class="org.apache.mina.filter.logging.LoggingFilter" ></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="logger" />
</map>
</property>
</bean>
</beans>

#5


我记得MINA的demo很简单的吧。不要用telnet测。直接写个官方的demo

#6


引用 1 楼 u010245868 的回复:
telnet是TCP传输的协议, 你配置的是UDP    0.0.0.0:8888  *:*  4532,是UDP

udp用telnet没法测得,下载个专业工具吧

#1


telnet是TCP传输的协议, 你配置的是UDP    0.0.0.0:8888  *:*  4532,是UDP

#2


对呀,在哪配置的?

#3


下面是我的配置 给你参考一下 

<?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:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" default-autowire="byName">                 


<!-- 配置IP -->
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.net.InetSocketAddress">
<bean class="org.apache.mina.integration.beans.InetSocketAddressEditor" />
</entry>
</map>
</property>
</bean>

<!-- 配置service  -->
<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor" 
init-method="bind" destroy-method="unbind" >
<property name="defaultLocalAddress" value=":6007" />
<property name="handler" ref="testServiceHandler" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
<!-- <bean  class="org.apache.mina.transport.socket.DefaultSocketSessionConfig" >
<property name="bothIdleTime" value="10"></property>
<property name="readBufferSize" value="2048"></property>
</bean> -->

</bean>


<!-- 配置业务处理类 -->
<bean id="testServiceHandler" class="com.mina.test.service.TestServiceHandler">
</bean>

<!-- 配置数据库操作工具类 
<bean id="du" class="com.mina.test.util.DaoUtil">
</bean>-->

<!-- 配置解码器 -->
<bean id="codec" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg>
<bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory" />
</constructor-arg>
</bean>

<!-- 配置日志拦截器 -->
<bean id="logger" class="org.apache.mina.filter.logging.LoggingFilter" ></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="logger" />
</map>
</property>
</bean>
</beans>

#4


#5


我记得MINA的demo很简单的吧。不要用telnet测。直接写个官方的demo

#6


引用 1 楼 u010245868 的回复:
telnet是TCP传输的协议, 你配置的是UDP    0.0.0.0:8888  *:*  4532,是UDP

udp用telnet没法测得,下载个专业工具吧