Java 远程调用之Hessian简例
来源:互联网 发布:老版本知乎2.4.4 编辑:程序博客网 时间:2024/05/17 22:46
1,导入jar包
<dependency><groupId>org.resthub</groupId><artifactId>hessian</artifactId><version>4.0.8</version></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.3.3</version></dependency>
2,提供接口
/** * 服务接口 */public interface ISayHelloService {/** * @param name * @return */String doSayHello(String name);
}
3,提供实现类
/** * 服务接口实现 */@Servicepublic class SayHelloServiceImpl implements ISayHelloService {public String doSayHello(String name) {return doSayHello(name, "hello");}}
<servlet> <servlet-name>hessian</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/hessian-servlet.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>hessian</servlet-name> <url-pattern>/hessian/*</url-pattern> </servlet-mapping>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"default-lazy-init="false"><bean id="defaultHandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /><context:component-scan base-package="com.rpc.service.impl"/><!-- 测试 --><bean id="sayHelloService" class="com.rpc.service.impl.SayHelloServiceImpl" /> <bean id="/hello" class="org.springframework.remoting.caucho.HessianServiceExporter"><property name="service" ref="sayHelloService" /><!-- 服务接口 --><property name="serviceInterface" value="com.hatchet.rpc.service.ISayHelloService" /></bean></beans>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> <context:property-placeholder ignore-resource-not-found="true"location="classpath*:/application.properties" /> <bean id="hello" class="org.springframework.remoting.caucho.HessianProxyFactoryBean"> <property name="serviceUrl" value="http://${rpc.server.ip}:${rpc.server.port}/crowdfunding-rpc-server/hessian/hello" /> <property name="serviceInterface" value="com.hatchet.rpc.service.ISayHelloService" /> <property name="overloadEnabled" value="true" /> <property name="readTimeout" value="${rpc.readTimeout}" /> </bean></beans>application.properties文件
rpc.server.ip=127.0.0.1rpc.server.port=8080rpc.readTimeout=60000
大功告成,通过spring注入接口调用服务即可
0 0
- Java 远程调用之Hessian简例
- Java远程调用之Hessian
- Java 远程调用 Hessian 简例
- Java远程调用之Hessian篇简例
- java远程调用之spring和hessian
- Hessian-远程服务调用
- Hessian实现远程调用
- spring hessian远程调用
- 浅尝Hessian远程调用
- Hessian远程调用框架进阶教程(一) Hessian介绍JAVA使用Hessian进行编程实例
- Hessian 远程调用框架(Java跨工程调用接口)
- 远程调用之RMI、Hessian、Burlap、Httpinvoker、WebService的比较
- 远程服务调用之RMI、Hessian、Burlap、Spring的HTTPinvoker
- java框架简介4----Spring+Hessian 远程过程调用
- Hessian---java远程通讯
- hessian 实现远程接口调用
- hessian远程调用的使用
- hessian 远程接口调用原理
- MFC编程之添加拖动文件获取文件路径功能
- Android 动态修改TextView 颜色Color
- Android中修改默认字体的大小----fontScale
- 第一篇博客
- 微信公众号开发--自定义菜单失败40033解决方案
- Java 远程调用之Hessian简例
- 【数据结构学习】二叉树
- [OpenGL ES 05]相对空间变换及颜色
- 【C语言】静态线性顺序表
- 正则表达式示例。
- jsbin-jsfiddle-or-codepen-which-one-to-use-and-why
- 学习
- fasdfsaf
- zookeeper原理(转)