欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

容易spring+hessian

更新时间: 2014-01-05 00:50:30 责任编辑: Author_N1

 

简单Spring+hessian
<div class="iteye-blog-content-contain" style="font-size: 14px">
简单的Spring+hessian
           
Jar包:
dist\modules里面的 spring-webmvc.jar 
lib\caucho 里面的hessian-3.1.3.jar
Server:
里面有个接口interface:
public interface IBasic {

public String helloWorld();
public User getUser();
}
接口的实现:
public class IBasicServer implements IBasic {
@Override
public String helloWorld() {
return "hello world!!";
}
@Override
public User getUser() {
User user =new User();
user.setName("nie");
user.setPassword("123");
return user;
}
}
建立一个model层:(实现Serializable接口)
public class User implements Serializable {

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
private String name;
private String password;
}

Web.xml里面配置:
<servlet>
    <servlet-name>remoting</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
 
<servlet-mapping>
    <servlet-name>remoting</servlet-name>
    <url-pattern>/remoting/*</url-pattern>
</servlet-mapping>

在WEB-INF下面创建一个remoting-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="accountService" class="nie.wei.qing.Server.implment.IBasicServer">
</bean>

<bean name="/AccountService" class="org.springframework.remoting.caucho.HessianServiceExporter">
    <property name="service" ref="accountService"/>
    <property name="serviceInterface" value="nie.wei.qing.Server.IBasic"/>
</bean>

</beans>



客户端同样的要有interface  IBasic  和model层  User(实现Serializable接口)
在src下面建立一个remote-client.xml
<bean id="accountService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
    <property name="serviceUrl" value="http://localhost:8080/Hissian-Server/remoting/AccountService"/>
    <property name="serviceInterface" value="nie.wei.qing.Server.IBasic"/>
</bean>

使用JUnit来测试;测试代码:
try
{
ApplicationContext context = new ClassPathXmlApplicationContext("remote-client.xml");

IBasic basic =(IBasic)context.getBean("accountService");

System.out.println(basic.helloWorld());
}
catch (Exception e)
{
e.printStackTrace();
}</div>
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 00:50:30
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/402/
本文WWW.DOC100.NET DOC100.NET版权所有。