用Spring开发Hessian服务实例说明

 

一.服务端web程序配置要点:

1.WEB-INF/lib目录下增加:spring-2.0.7.jar,hessian-3.0.13.jar等包;

2.WEB-INF/web.xml中增加Hessian服务和Spring容器配置:

 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
   /WEB-INF/conf/spring/applicationContext.xml  
   /WEB-INF/conf/spring/beans-data-source.xml 
   /WEB-INF/conf/spring/beans-dao.xml
   /WEB-INF/conf/spring/beans-bo.xml   
   /WEB-INF/remoting-servlet.xml
  </param-value>
 </context-param>
 <context-param>
  <param-name>log4jConfigLocation</param-name>
  <param-value>/WEB-INF/conf/log4j.properties</param-value>
 </context-param>
 <context-param>
  <param-name>log4jExposeWebAppRoot</param-name>
  <param-value>true</param-value>
 </context-param>
 <context-param>
  <param-name>log4jRefreshInterval</param-name>
  <param-value>1000</param-value>
 </context-param>
 
 <listener>
  <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 </listener>
 <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>

3. 增加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.0.xsd">

 <bean name="/userService" class="org.springframework.remoting.caucho.HessianServiceExporter">
    <property name="service" ref="userBO"/>
    <property name="serviceInterface" value="com.sw.tangseng.admin.bo.UserBO"/>
 </bean> 
</beans>

 4.配置实例中Spring的业务对象 /WEB-INF/conf/spring/beans-bo.xml ,Spring的其他配置略:

<?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="userBO" class="com.sw.tangseng.admin.bo.impl.UserBOImpl">
  <property name="userDAO">
           <ref bean="userDAO" />
     </property>
    </bean>
</beans>

5.使用到的传输对象DataObject必须序列化,如下:

import java.io.Serializable;

public class UserDO implements Serializable {
 private static final long serialVersionUID = 8935029394766425585L;

 /**
     * This field was generated by Abator for iBATIS.
     * This field corresponds to the database column T_USER.id
     *
     * @abatorgenerated Wed Apr 09 09:43:08 CST 2008
     */
    private Integer id;

    /**
     * This field was generated by Abator for iBATIS.
     * This field corresponds to the database column T_USER.user_name
     *
     * @abatorgenerated Wed Apr 09 09:43:08 CST 2008
     */
    private String user_name;

    /**
     * This field was generated by Abator for iBATIS.
     * This field corresponds to the database column T_USER.user_pwd
     *
     * @abatorgenerated Wed Apr 09 09:43:08 CST 2008
     */
    private String user_pwd;

    /**
     * This method was generated by Abator for iBATIS.
     * This method returns the value of the database column T_USER.id
     *
     * @return the value of T_USER.id
     *
     * @abatorgenerated Wed Apr 09 09:43:08 CST 2008
     */
    public Integer getId() {
        return id;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method sets the value of the database column T_USER.id
     *
     * @param id the value for T_USER.id
     *
     * @abatorgenerated Wed Apr 09 09:43:08 CST 2008
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method returns the value of the database column T_USER.user_name
     *
     * @return the value of T_USER.user_name
     *
     * @abatorgenerated Wed Apr 09 09:43:08 CST 2008
     */
    public String getUser_name() {
        return user_name;
    }


 /**
     * This method was generated by Abator for iBATIS.
     * This method sets the value of the database column T_USER.user_name
     *
     * @param user_name the value for T_USER.user_name
     *
     * @abatorgenerated Wed Apr 09 09:43:08 CST 2008
     */
    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method returns the value of the database column T_USER.user_pwd
     *
     * @return the value of T_USER.user_pwd
     *
     * @abatorgenerated Wed Apr 09 09:43:08 CST 2008
     */
    public String getUser_pwd() {
        return user_pwd;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method sets the value of the database column T_USER.user_pwd
     *
     * @param user_pwd the value for T_USER.user_pwd
     *
     * @abatorgenerated Wed Apr 09 09:43:08 CST 2008
     */
    public void setUser_pwd(String user_pwd) {
        this.user_pwd = user_pwd;
    }
}

服务端配置到此结束,下面讲客户端的调用配置。

 

二.客户端调用配置:

1.WEB-INF/lib目录下增加:spring-2.0.7.jar,hessian-3.0.13.jar等包;

2.WEB-INF/web.xml中Spring的配置:

 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
   /WEB-INF/conf/spring/applicationContext.xml  
   /WEB-INF/conf/spring/beans-data-source.xml 
   /WEB-INF/conf/spring/beans-dao.xml
   /WEB-INF/conf/spring/beans-bo.xml   
  </param-value>
 </context-param>
 <context-param>
  <param-name>log4jConfigLocation</param-name>
  <param-value>/WEB-INF/conf/log4j.properties</param-value>
 </context-param>
 <context-param>
  <param-name>log4jExposeWebAppRoot</param-name>
  <param-value>true</param-value>
 </context-param>
 <context-param>
  <param-name>log4jRefreshInterval</param-name>
  <param-value>1000</param-value>
 </context-param>
 
 <listener>
  <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 </listener>
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

3.Spring的Bean的配置如下:

<?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="userClientBO" class="com.sw.tangseng.admin.bo.impl.ImplCityBO">
  <property name="userBO">
           <ref bean="userService" />
     </property>     
    </bean>

    <!--  使用HessianProxyFactoryBean 连接远程Hessian服务-->
    <bean id="userService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
         <property name="serviceUrl" value="http://127.0.0.1:8090/vote/remoting/userService"/>
         <property name="serviceInterface" value="com.sw.tangseng.admin.bo.UserBO"/>
    </bean>

</beans>

所有关键配置结束! :)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值