本章中演示在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. html5时间选择器

    HTML5日期输入类型(date)   分享   分享   分享   分享   分享 在很多页面和web应用中都有输入日期和时间的地方,最典型的是订飞机票,火车票,酒店,批萨等网站. 在HTML5之前 ...

  2. jquery前端性能优化(持续添加。。。)

    1.选择器的使用 (1)$('#id')   使用id来定位dom元素是性能最高的方法.jQuery底层将直接调用本地方法document.getElementById().如果id直接可以找到所要对 ...

  3. Linux 多用户和多用户边界

    1. 需求背景 2. 多用户的边界: 独立的工作目录 3. 多用户的边界:可操作/访问的资源 4. 多用户的边界: 可执行的操作 5. 多用户的特性标识: UID和GID -------------- ...

  4. ASP.NET 后台不识别ASPX中的控件

    请问后台不识别ASPX中的控件,怎么解决 这个程序是在网上下载的 C# code <asp:DataGrid runat="server" ID="dgList1& ...

  5. 结合使用 Oracle Database 11g 和 Python

    结合使用 Oracle Database 11g 和 Python 本教程介绍如何结合使用 Python 和 Oracle Database 11g. 所需时间 大约 1 个小时 概述 Python ...

  6. C# this.Invoke()的作用和用法(摘)

    Invoke()的作用是:在应用程序的主线程上执行指定的委托.一般应用:在辅助线程中修改UI线程( 主线程 )中对象的属性时,调用this.Invoke();   在多线程编程中,我们经常要在工作线程 ...

  7. 学习Swift -- 数组(Array) - 持续更新

    集合类型--数组 Array是Swift中的一种集合类型:数组,数组是使用有序列表储存同一类型的多个值,与OC的NSArray的最大不同是,Swift的数组是值类型,OC的数组是引用类型 声明数组的方 ...

  8. django中的事务管理

    在讲解之前首先来了解一下数据库中的事务. 什么是数据库中的事务? 热心网友回答: ():事务(Transaction)是并发控制的单位,是用户定义的一个操作序列.这些操作要么都做,要么都不做,是一个不 ...

  9. JavaWeb 文件上传 commons_fileupload方式

    import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadExcept ...

  10. 《More Effective C++》 条款5 谨慎定义类型转换函数

    ---恢复内容开始--- C++编译器能够在两种数据类型之间进行隐式转换(implicit conversions),它继承了C语言的转换方法,例如允许把char隐式转换为int和从short隐式转换 ...