hessian简单示例
Posted 唐大麦
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hessian简单示例相关的知识,希望对你有一定的参考价值。
创建一个对外接口
public interface Basic
String hello(String name);
String say(String msg);
int sum(int a,int b);
实现该接口并继承HessianServlet
public class BasicService extends HessianServlet implements Basic
@Override
public String hello(String name)
return "Hello " + name;
@Override
public int sum(int a, int b)
return a + b;
@Override
public String say(String msg)
return "Say:" + msg;
配置web.xml
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.abel533.hessian.BasicService</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
启动服务器
客户端代码
public class Client
interface Hello
String hello(Object name);
interface SumSay
String say(String msg);
int sum(int a, int b);
int hi(String hi);
public static void main(String[] args) throws MalformedURLException
//TODO 根据实际地址修改
String url = "http://localhost:8090/hello";
HessianProxyFactory factory = new HessianProxyFactory();
Hello basic = (Hello) factory.create(Hello.class, url);
System.out.println(basic.hello(123));
SumSay sumSay = (SumSay) factory.create(SumSay.class, url);
System.out.println(sumSay.say("你好!"));
System.out.println("10+20=" + sumSay.sum(10, 20));
在客户端中创建了两个接口,接口名和最上面Basic中的部分接口是一样的。
经过简单的测试发现,只要方法名一致,并且参数个数一致,就可以成功调用。
以上是关于hessian简单示例的主要内容,如果未能解决你的问题,请参考以下文章
警告: Hessian/Burlap: 'com.github.pagehelper.Page' is an unknown class in WebappClassLoader(示例