Spring HTTP invoker简介
2013-06-15 15:59
459 查看
UcService service = (UcService) WebApplicationContextUtils .getRequiredWebApplicationContext( request.getSession().getServletContext()).getBean( "httpService"); UserInfo user = service.getUserInfobyName("hanqunfeng");
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/httpService">httpService</prop> </props> </property> </bean>
Spring HTTP invoker简介 Spring HTTP invoker是spring框架中的一个远程调用模型,执行基于HTTP的远程调用(意味着可以通过防火墙),并使用java的序列化机制在网络间传递对象。客户端可以很轻松的像调用本地对象一样调用远程服务器上的对象,这有点类似于we
Spring HTTP invoker简介
Spring HTTP invoker是spring框架中的一个远程调用模型,执行基于HTTP的远程调用(意味着可以通过防火墙),并使用java的序列化机制在网络间传递对象。客户端可以很轻松的像调用本地对象一样调用远程服务器上的对象,这有点类似于webservice,但又不同于webservice,区别如下:
webservice | HTTP invoker |
跨平台,跨语言 | 只支持java语言 |
支持SOAP,提供wsdl | 不支持 |
结构庞大,依赖特定的webservice实现,如xfire等 | 结构简单,只依赖于spring框架本身 |
Server端:
1、在context中注册bean
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/httpService">httpService</prop> </props> </property> </bean>
2、 在web.xml中注册servlet
<context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/application-context.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>service</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>service</servlet-name> <url-pattern>/service/*</url-pattern> </servlet-mapping>
3、 在WEB-INF下增加service-servlet.xml(文件名为 web.xml中的servlet名称(此处为service)+"-servlet.xml")
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/httpService">httpService</prop> </props> </property> </bean>
于是发布成http://${serviceName}:${port}/${contextPath}/service/httpService 的服务。
客户端
1、 配置bean
<bean id="httpService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl"> <value> http://${serviceName}:${port}/${contextPath}/service/httpService </value> </property> <property name="serviceInterface" value="com.netqin.baike.service.UcService"> </property> </bean>
2、 按照普通bean的获取方式获得实例,然后调用接口:
UcService service = (UcService) WebApplicationContextUtils.getRequiredWebApplicationContext( request.getSession().getServletContext()).getBean("httpService"); UserInfo user = service.getUserInfobyName("hanqunfeng");
相关文章推荐
- Spring Http Invoker使用简介
- Spring Http Invoker使用简介
- Spring HTTP invoker简介
- Spring HTTP invoker 简介
- Spring HTTP invoker简介
- Spring HTTP invoker简介
- Spring Http Invoker使用简介
- Spring HTTP invoker简介
- Spring Http Invoker使用简介
- Spring HTTP invoker简介
- spring httpInvoker中前后台byte[]数据传输
- Spring HTTP Invoker 学习小记
- Spring HttpInvoker源码分析
- Spring的HTTPInvoker
- Spring中HttpInvoker远程方法例子
- Spring HTTP Invoker使用介绍
- 关于spring http invoker中一个常见错误,dubbo 调用 hibernate的set map list
- org.springframework.remoting.RemoteConnectFailureException: Could not connect to HTTP invoker remote
- Spring HttpInvoker 开发
- Spring HTTP Invoker 学习小记