本章中演示在Spring中整合Mina,为了整合到Spring,需要做以下几个步骤:

1. 设置IoHandler

<bean id="trapHandler" class="com.ashishpaliwal.udp.mina.server.ServerHandler">

2. 创建Filters并加入到Chain中

<bean id="snmpCodecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
<constructor-arg>
<bean class="com.ashishpaliwal.udp.mina.snmp.SNMPCodecFactory" />
</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>

3. 创建IoAcceptor

<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=":161" />
<property name="handler" ref="trapHandler" />
<property name="filterChainBuilder" ref="filterChainBuilder" />
</bean>

4. 在spring启动时加载该xml文件

public void initializeViaSpring() throws Exception {
new ClassPathXmlApplicationContext("trapReceiverContext.xml");
}

Mina学习之与Spring整合的更多相关文章

  1. Spring学习笔记:spring整合web之spring-web架包的引用(WebApplicationContextUtils注入容器)

    WebApplicationContextUtils 一.Spring整合web之前 案例:给部门列表添加新部门 import org.apache.log4j.Logger; import org. ...

  2. Spring学习笔记:Spring整合Mybatis(mybatis-spring.jar)(二:mybatis整合spring)

    http://blog.csdn.net/qq598535550/article/details/51703190 二.Spring整合mybatis其实是在mybatis的基础上实现Spring框架 ...

  3. Java开发学习(十四)----Spring整合Mybatis及Junit

    一.Spring整合Mybatis思路分析 1.1 环境准备 步骤1:准备数据库表 Mybatis是来操作数据库表,所以先创建一个数据库及表 create database spring_db cha ...

  4. 【Activiti学习之八】Spring整合Activiti

    环境 JDK 1.8 MySQL 5.6 Tomcat 8 idea activiti 5.22 activiti-explorer是官方提供的一个演示项目,可以使用页面管理Activiti流程.ac ...

  5. Spring学习笔记:Spring整合Mybatis学习PPT(三:整合思路)

    三.Spring-Mybatis的整合思路

  6. Spring学习笔记:Spring整合Mybatis(mybatis-spring.jar)(一:知识点回顾)

    一.知识点回顾 1.Mybatis环境搭建(DAO层的实现)(使用maven项目管理工具) 需要引入的依赖包: <!-- 单元测试junit --> <dependency> ...

  7. 【mybatis源码学习】与spring整合Mapper接口执行原理

    一.重要的接口 org.mybatis.spring.mapper.MapperFactoryBean MapperScannerConfigurer会向spring中注册该bean,一个mapper ...

  8. mybatis与spring整合时读取properties问题的解决

    在学习mybatis与spring整合是,想从外部引用一个db.properties数据库配置文件,在配置文件中使用占位符进行引用,如下: <context:property-placehold ...

  9. 分布式缓存技术redis学习系列(五)——redis实战(redis与spring整合,分布式锁实现)

    本文是redis学习系列的第五篇,点击下面链接可回看系列文章 <redis简介以及linux上的安装> <详细讲解redis数据结构(内存模型)以及常用命令> <redi ...

随机推荐

  1. wordpress4.0.1源码学习和摘录--项目设置

    1.静态变量日期 define( 'MINUTE_IN_SECONDS', 60 ); define( 'HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS ); def ...

  2. Window 下安装Redis

    下载地址:https://github.com/dmajkic/redis/downloads. 下载到的Redis支持32bit和64bit.根据自己实际情况选择,将64bit的内容cp到自定义盘符 ...

  3. ubuntu下Qt之android环境配置以及一些常见问题解决

    准备材料有: 1. qt for android 5.×版本,下载地址如下,可以选择一个合适自己机器型号的版本进行下载. 地址:http://www.qt.io/download-open-sourc ...

  4. 链表与Hash检索实测

    测试环境: Win7 SP1.8G内存.3.4GHz 4核 测试代码: using System; using System.Collections.Generic; using System.Lin ...

  5. scrollview 例子2

    代码: #import "RootViewController.h" @implementation RootViewController @synthesize scrollVi ...

  6. 转载:如何避免代码中的if嵌套

    http://top.jobbole.com/4960/ http://stackoverflow.com/questions/24430504/how-to-avoid-if-chains 在Sta ...

  7. hdu3949 XOR xor高斯消元

    XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  8. [BZOJ 1040] [ZJOI2008] 骑士 【基环+外向树DP】

    题目链接:BZOJ - 1040 题目分析 这道题目的模型就是一个图,不一定联通,每个连通块的点数等于边数. 每个连通块都是一个基环+外向树.即树上增加了一条边. 如果是树,就可以直接树形DP了.然而 ...

  9. 安卓天天练练(五)CompoundButton

    ToggleButton 让我想起了从前jQuery还没有取消toggle方法时是怎么偷懒的.. 注意: 如果LinearLayout,与RelativeLayout不同,必须有orientation ...

  10. Unity3d 物理 Rigidbody预防穿插

    Unity3d 物理 Rigidbody预防穿插 @广州小龙 Unity的物理引擎采用的是Physx引擎,里面的组件是Rigidbody!这个可以模拟物理效果! Rigidbody,这个是可以进行穿插 ...