简单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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值