java httpinvoke_spring httpInvoke 解决远程调用远程的类的方法

spring httpInvoke 基于spring架构的服务器之间的远程调用实现。通过spring httpInvoke,可以调用远程接口,进行数据交互、业务逻辑操作

服务器端:(被调用一方)

public  class User implements Serializable{//必须实现serializable接口,远程调用的基础

private String username;

private Date birthday;

//构造方法

//set get 方法

}

public interface UserService{

User getUser(String username);

}

public UserServiceImpl implements UserService{

//实现userService

}重要的配置文件来了。。。。remote-servlet.xml放在项目根目录下面,跟web.xml相同的级别

暴露给调用端:服务的实现,接口

com.cd.Liaq.UserService

暴露了服务的实现和接口,那么怎么访问服务呢?spring封装访问url

第一种:

第二种:userService

web.xml:配置dispatcherServlet共调用一方使用

remote

org.springframework.web.servlet.DispatcherServlet

1

remote

/remoting/*

到处为止:被调用端一方完毕!!!!客户端调用:

class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">

http://192.9.200.123:8080/MemberSystem/remoting/memberService

com.cd.Liaq.UserService

通过spring容器调用UserService,用到HttpInvokerProxyFactoryBean工厂,配置serviceUrl和serviceInterface为了提高效率:客户端使用Commons-HttpClient,导入改包,改写配置

class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">

http://192.9.200.123:8080/MemberSystem/remoting/memberService

com.cd.Liaq.UserService

 //使用指定的执行器执行

配置超时时间timeout和连接超时connectionTimeout两个属性优化执行器:多线程===被调用端响应时间缩短很多

//控制连接

httpClient的3.1版本不支持这种配置

另外httpClient本身也是多线程的。。HttpClient that uses a default MultiThreadedHttpConnectionManagemaxConnectionsPerHost 每个主机的最大并行链接数,默认为2public static final int DEFAULT_MAX_HOST_CONNECTIONS = 2;maxTotalConnections 客户端总并行链接最大数,默认为20public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20;

posted on 2016-06-19 10:29 youngturk 阅读(1874) 评论(0)  编辑  收藏 所属分类: 笔试题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值