admin 管理员组文章数量: 887021
2024年2月24日发(作者:变量名命名的原则有哪些)
ApacheMINA和SpringMVC集成1.创建项目创建一个SpringMVC的WEB应用项目,导入SpringMVC相关的jar包。另外还需要导入支持Spring面向切面编程的几个包,如下:两个日志相关的包,如下:
另外导入MINA的包,如下:2.配置1)配置其实就是SpringMVC的相关配置。
2)配置也是很普通宾配置项。 /schema/tx/schema/tx/"> class="ketAcceptor"init-method="bind"destroy-method="unbind"> }publicvoidsessionIdle(IoSessionsession,IdleStatusstatus){//();}//publicvoidsessionClosed(IoSessionsession)throwsException{//(session);//}publicvoidexceptionCaught(IoSessionsession,Throwablecause){("Unexpectedexception.",cause);();}}2)客户端程序下面是二个测试用的客户端程序:1、这个Client端设置的handler程序,是用于接收服务端回复过来的信息用的。;er;ion;lerAdapter;olCodecFilter;gFilter;neCodecFactory;publicclassMinaClientHandlerextendsIoHandlerAdapter{privatestaticfinalIoFilterLOGGING_FILTER=newLoggingFilter();privatestaticfinalIoFilterCODEC_FILTER=newProtocolCodecFilter(newTextLineCodecFactory());@OverridepublicvoidsessionCreated(IoSessionsession)throwsException{terChain().addLast("codec",CODEC_FILTER);terChain().addLast("logger",LOGGING_FILTER); }@OverridepublicvoidmessageReceived(IoSessionsession,Objectmessage)Stringmsg=(String)message;}}throwsException{n("ClientReceived:"+msg);2、这个客户端的主应用程序,负责发送客户端的请求到服务器端。;cketAddress;Address;tFuture;ler;ion;ectionFilter;ketConnector;publicclassMinaClientSupport{privateIoHandlerhandler=null;privateIoSessionsession;privateStringhost;privateintport;publicbooleansend(Objectmessage){if(session!=null&&ected()){thrownewIllegalStateException("nectfirst.");}SocketAddressaddress=newInetSocketAddress(host,port);NioSocketConnectorconnector=newNioSocketConnector();try{terChain().addLast("mdc",newMdcInjectionFilter()); dler(handler);ConnectFuturefuture1=t(address);ninterruptibly();if(!ected()){}returnfalse;session=sion();(message);}catch(Exceptione){}returnfalse;returntrue;}publicvoidclose(){if(session!=null){if(ected()){//Waituntilthechatends.}}seFuture().awaitUninterruptibly();();}publicStringgetHost(){}returnhost;publicvoidsetHost(Stringhost){}=host;publicintgetPort(){}returnport;publicvoidsetPort(intport){}=port;publicvoidsetHandler(IoHandlerhandler){}r=handler;publicstaticvoidmain(String[]args){ n("---------------------");MinaClientSupportclient=newMinaClientSupport();dler(handler);t(1235);(msg);();MinaClientHandlerhandler=newMinaClientHandler();t("localhost");Stringmsg="helloworld!";n("ClientSend:"+msg);}}
版权声明:本文标题:Apache MINA和Spring MVC集成 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1708773027h531005.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论