Spring 企业级开发应用---------hessian和spring的远程服务整合的应用

hessian和burlap使用同一公司的产品实现机制不同,但是他们的配置一样所以在仅仅提供代码参考,

具体上一节spring和burlap的远程服务的整合的应用

 

服务端接口

package cn.com.huawei.hessian.service;

import java.util.List;

public interface IUserService {
  public List getUsernames();
}

服务端接口的实现

package cn.com.huawei.hessian.service.impl;

import java.util.ArrayList;
import java.util.List;

import cn.com.huawei.hessian.service.IUserService;

public class UserService  implements  IUserService{
   public List getUsernames()
   {
     List<String> usernames=new ArrayList<String>();
     usernames.add("xiaobai");
     usernames.add("xiaoli");
     return usernames;
   }
}

 

服务端的web。xml的配置信息

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
 </context-param>
 <listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>
 <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>
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

applicationContext。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.0.xsd">
     
       <bean id="userservicetarget" class="cn.com.huawei.hessian.service.impl.UserService"/>
</beans>

 

 

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.0.xsd">
  
   
  
 
  <bean name="/Userservice-hessina" class="org.springframework.remoting.caucho.HessianServiceExporter">
    <property name="service">
      <ref bean="userservicetarget"/>
    </property>
    <property name="serviceInterface">
      <value>cn.com.huawei.hessian.service.IUserService</value>
    </property>
  </bean>
</beans>

 

关于客户端信息如下:

 

 

client.properties属性文件的信息

# Properties file with server URL settings for remote access.
# Applied by PropertyPlaceholderConfigurer from "clientContext.xml".

serverName=localhost
httpPort=8080
rmiPort=1099
serverPath=SpringHessian
contextPath=remoting/Userservice-hessina

 

spring和hessian的配置信息

<?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.0.xsd">
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="location"><value>client.properties</value></property>
 </bean>
    <bean id="hessinaclient" class="cn.com.huawei.hessian.client.HessinaClient">
      <property name="userservice">
         <ref local="proxyuserservice" />
      </property>
    </bean>
   <bean id="proxyuserservice" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
        <property name="serviceUrl">
          <value>http://${serverName}:${httpPort}/${serverPath}/${contextPath}</value>
        </property>
    <property name="serviceInterface">
      <value>cn.com.huawei.hessian.service.IUserService</value>
    </property>
  </bean>
</beans>

 

客户端测试代码应用

package cn.com.huawei.hessian.client;

import java.util.List;

import cn.com.huawei.hessian.service.IUserService;

public class HessinaClient {

 private IUserService userservice;

 public IUserService getUserservice() {
  return userservice;
 }

 public void setUserservice(IUserService userservice) {
  this.userservice = userservice;
 }

 public List getUsernames() {
  return this.userservice.getUsernames();
 }

}

 

package cn.com.huawei.hessian.client;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HessianTest {
 public static void main(String[] args) {
  ApplicationContext ctx = new ClassPathXmlApplicationContext(
    "applicationContext.xml");
  HessinaClient hessina = (HessinaClient) ctx.getBean("hessinaclient");
  System.out.println("hessinaclient:" + hessina.getUsernames());
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值