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) 编辑 收藏 所属分类: 笔试题