首页 > 编程语言 > 详细

spring httpInvoke 解决远程调用远程的类的方法

时间:2016-06-20 02:01:21      阅读:652      评论:0      收藏:0      [点我收藏+]

spring httpInvoke 解决远程调用远程的类的方法

http://zhidao.baidu.com/link?url=6FrnwvBQEZhjM-ooNCuiAra7T6qi9FsFhFvkHBKaOjqovZR86OCsIePi-05nM-fxRrlInEGbElSxlhgO6X7JsaGNdQdNrQ2xE58wglgeQO3 http://blog.csdn.net/liaq325/article/details/8281550 摘自以上 spring httpInvoke 基于spring架构的服务器之间的远程调用实现。通过spring httpInvoke,可以调用远程接口,进行数据交互、业务逻辑操作 服务器端:(被调用一方) [java] view plain copy 01.public class User implements Serializable{//必须实现serializable接口,远程调用的基础 02. private String username; 03. private Date birthday; 04. //构造方法 05. //set get 方法 06.} 07.public interface UserService{ 08. User getUser(String username); 09.} 10.public UserServiceImpl implements UserService{ 11. //实现userService 12.} 重要的配置文件来了。。。。 remote-servlet.xml放在项目根目录下面,跟web.xml相同的级别 暴露给调用端:服务的实现,接口 [html] view plain copy 01. 02. 03. 04. 05. 06. com.cd.Liaq.UserService 07. 08. 暴露了服务的实现和接口,那么怎么访问服务呢? spring封装访问url [html] view plain copy 01. 02. 第一种: 03. 04. 05. 06. 07. 第二种:userService 08. web.xml:配置dispatcherServlet共调用一方使用 [html] view plain copy 01. 02. 03. remote 04. org.springframework.web.servlet.DispatcherServlet 05. 1 06. 07. 08. remote 09. /remoting/* 10. 到处为止:被调用端一方完毕!!!! 客户端调用: [html] view plain copy 01. 02. 04. 05. http://192.9.200.123:8080/MemberSystem/remoting/memberService 06. 07. 08. com.cd.Liaq.UserService 09. 10. 通过spring容器调用UserService,用到HttpInvokerProxyFactoryBean工厂,配置serviceUrl和serviceInterface 为了提高效率:客户端使用Commons-HttpClient,导入改包,改写配置 [html] view plain copy 01. 03. 04. http://192.9.200.123:8080/MemberSystem/remoting/memberService 05. 06. 07. com.cd.Liaq.UserService 08. 09. //使用指定的执行器执行 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 配置超时时间timeout和连接超时connectionTimeout两个属性 优化执行器:多线程===被调用端响应时间缩短很多 [html] view plain copy 01. 02. 03. 04. 05. 06. //控制连接 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. httpClient的3.1版本不支持这种配置 [html] view plain copy 01. 02. 另外httpClient本身也是多线程的。。HttpClient that uses a default MultiThreadedHttpConnectionManage maxConnectionsPerHost 每个主机的最大并行链接数,默认为2 public static final int DEFAULT_MAX_HOST_CONNECTIONS = 2; maxTotalConnections 客户端总并行链接最大数,默认为20 public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20;

spring httpInvoke 解决远程调用远程的类的方法

原文:http://www.blogjava.net/youngturk/archive/2016/06/19/430960.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!