阿里云登陆服务器:Hessian入门(与Spring集成)
来源:百度文库 编辑:中财网 时间:2024/04/29 11:02:46
Hessian入门(与Spring集成)
Hessian入门(与Spring集成)
By:wtang
说明 :
1. 讲述如何配置Hessian的服务器端(与Spring集成).
2. 讲述客户端如何调用
① 使用HessianProxyFactory Hessian代理工厂直接调用
② 使用HessianProxyFactoryBean Hessian代理工厂Bean来完成接口调用.
1. 讲述如何配置Hessian的服务器端(与Spring集成).
接口定义类: com.wtang.isay. Isay:
view plain
package com.wtang.isay;
public interface Isay {
public String sayHello(String arg1,String arg2);
}
接口具体实现类: com.wtang.isay. IsayImpl
view plain
package com.wtang.isay;
public class IsayImpl implements Isay {
public String sayHello(String arg1, String arg2) {
return "Hello:" + arg1 + arg2;
}
}
配置Web.xml:
view plain
remote
org.springframework.web.servlet.DispatcherServlet
namespace
classes/remote-servlet
1
remote
/remote/*
配置remote-servlet.xml[该文件位于src目录下,即编译后存在与classes下]:
view plain
class="org.springframework.remoting.caucho.HessianServiceExporter">
注:
这个文件为什么叫remote-servlet.xml呢?
因为我们在web.xml中有配置:remote 。
所以remote-servlet.xml的文件名必须以
中配置的servlet-name作为文件名的开头,
且文件名的格式必须是[servlet-name]-servlet.xml格式,否则检测不到。
即:
classes/remote-servlet
所以文件名为remote-servlet.xml。
2. 讲述客户端如何调用
① 使用HessianProxyFactory Hessian代理工厂直接调用
即:
view plain
package com.wtang.test;
import java.net.MalformedURLException;
import com.caucho.hessian.client.HessianProxyFactory;
import com.wtang.isay.Isay;
public class NormalClient {
public static void main(String[] args) throws MalformedURLException {
//Spring Hessian代理Servelet
String url = "http://localhost:8080/HessianSpring/remote/helloSpring";
HessianProxyFactory factory = new HessianProxyFactory();
Isay api = (Isay) factory.create(Isay.class, url);
System.out.println(api.sayHello("chen", "weitang"));
}
}
输出Hello:chenweitang
2. 讲述客户端如何调用
② 使用HessianProxyFactoryBean Hessian代理工厂Bean来完成接口调用.
配置客户端 remote-client.xml:
view plain
http://localhost:8080/HessianSpring/remote/helloSpring
com.wtang.isay.Isay
调用:
view plain
package com.wtang.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.wtang.isay.Isay;
public class SpringClient {
public static void main(String[] args) {
ApplicationContext contex = new ClassPathXmlApplicationContext(
"remote-client.xml");
// 获得客户端的Hessian代理工厂bean
Isay i = (Isay) contex.getBean("clientSpring");
System.out.println(i.sayHello("chen", "weitang"));
}
}
输出Hello:chenweitang
Hessian入门(与Spring集成)
By:wtang
说明 :
1. 讲述如何配置Hessian的服务器端(与Spring集成).
2. 讲述客户端如何调用
① 使用HessianProxyFactory Hessian代理工厂直接调用
② 使用HessianProxyFactoryBean Hessian代理工厂Bean来完成接口调用.
1. 讲述如何配置Hessian的服务器端(与Spring集成).
接口定义类: com.wtang.isay. Isay:
view plain
package com.wtang.isay;
public interface Isay {
public String sayHello(String arg1,String arg2);
}
接口具体实现类: com.wtang.isay. IsayImpl
view plain
package com.wtang.isay;
public class IsayImpl implements Isay {
public String sayHello(String arg1, String arg2) {
return "Hello:" + arg1 + arg2;
}
}
配置Web.xml:
view plain
配置remote-servlet.xml[该文件位于src目录下,即编译后存在与classes下]:
view plain
注:
这个文件为什么叫remote-servlet.xml呢?
因为我们在web.xml中有配置:
所以remote-servlet.xml的文件名必须以
且文件名的格式必须是[servlet-name]-servlet.xml格式,否则检测不到。
即:
所以文件名为remote-servlet.xml。
2. 讲述客户端如何调用
① 使用HessianProxyFactory Hessian代理工厂直接调用
即:
view plain
package com.wtang.test;
import java.net.MalformedURLException;
import com.caucho.hessian.client.HessianProxyFactory;
import com.wtang.isay.Isay;
public class NormalClient {
public static void main(String[] args) throws MalformedURLException {
//Spring Hessian代理Servelet
String url = "http://localhost:8080/HessianSpring/remote/helloSpring";
HessianProxyFactory factory = new HessianProxyFactory();
Isay api = (Isay) factory.create(Isay.class, url);
System.out.println(api.sayHello("chen", "weitang"));
}
}
输出Hello:chenweitang
2. 讲述客户端如何调用
② 使用HessianProxyFactoryBean Hessian代理工厂Bean来完成接口调用.
配置客户端 remote-client.xml:
view plain
调用:
view plain
package com.wtang.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.wtang.isay.Isay;
public class SpringClient {
public static void main(String[] args) {
ApplicationContext contex = new ClassPathXmlApplicationContext(
"remote-client.xml");
// 获得客户端的Hessian代理工厂bean
Isay i = (Isay) contex.getBean("clientSpring");
System.out.println(i.sayHello("chen", "weitang"));
}
}
输出Hello:chenweitang
jsp 与 struts hibernate spring 的关系
资源集成与能力集成
游泳入门与教学
谁知道hibernate3的与spring的详细配置
显卡集成与非集成的区别?
游泳如何入门与提高?
游泳如何入门与提高?
游泳如何入门与提高?
游泳如何入门与提高?
游泳如何入门与提高?
游泳如何入门与提高?
游泳如何入门与提高?
游泳如何入门与提高?
游泳如何入门与提高?
游泳如何入门与提高?
游泳如何入门与提高?
竖笛的入门与提高
服装设计入门指导与技巧
集成网卡与独立网卡
ERP与SCM如何集成
集成电路设计与集成系统 zhuyaofazhanqianjing
AD与DHCP怎么集成
spring是什么意思
pierian spring