zoukankan      html  css  js  c++  java
  • hessian 在spring中的使用 (bean 如 Dao无法注入的问题)

    hessian的主要结构分客户端与服务端,中间基于http传输。客户端主要做的事情是把对远程接口调用序列化为流,并传输到服务端;服务端主要做的事情是把传输过来的流反序列化为对服务的请求,调用相应服务后把结果序列化为流返回给客户端。一次完整的调用如下图所示:

     

    HessianProxy是hessian client处理客户端请求的核心类,它采用proxy的设计模式,代理客户端对远程接口的调用,hessian client的主流程的时序图如下所示:

     

    HessianSkeleton是hessian server端的核心类,从输入流中返序列化出客户端调用的方法和参数,对服务端服务进行调用,然后把处理结果返回给客户端,主要流程时序图如下所示:

     



    错误配置(不需要配置bean id="",因为此实现类直接在class中用注解配置,交由spring管理。):

        <!-- <bean id="dataCommBizServiceImpl" class="com.xinwei.process.service.impl.DataCommBizServiceImpl"></bean> -->
        <bean name="/dataCommBiz" class="org.springframework.remoting.caucho.HessianServiceExporter">
            <property name="service" ref="dataCommBizServiceImpl" />
            <property name="serviceInterface" value="com.xinwei.process.service.DataCommBizService" />
        </bean>
        classpath下新建hessian
    -servlet.xml ,注意这里不要定义 bean id ="" ,否则会导致hessain接口实现类中通过注解注入spring 中的bean 如 Dao时无法注入,出现null 异常

    INFO: Initializing Spring FrameworkServlet 'hessianServlet'
    2017-03-30 08:51:47,722 [localhost-startStop-1] INFO  [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping] - Mapped URL path [/sayHello] onto handler '/sayHello'
    2017-03-30 08:51:47,723 [localhost-startStop-1] INFO  [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping] - Mapped URL path [/dataCommBiz] onto handler '/dataCommBiz'
    2017-03-30 08:51:47,723 [localhost-startStop-1] INFO  [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping] - Mapped URL path [/dataPrivilege] onto handler '/dataPrivilege'
    2017-03-30 08:51:47,782 [localhost-startStop-1] INFO  [org.springframework.web.servlet.DispatcherServlet] - FrameworkServlet 'hessianServlet': initialization completed in 245 ms
    三月 30, 2017 8:51:47 上午 org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-bio-8080"]
    三月 30, 2017 8:51:47 上午 org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["ajp-bio-8009"]
    三月 30, 2017 8:51:47 上午 org.apache.catalina.startup.Catalina start
    INFO: Server startup in 14562 ms
    server method invoked!
    服务端方法被调用!
    2017-03-30 08:52:17,349 [http-bio-8080-exec-4] DEBUG [com.xinwei.process.service.impl.DataCommBizServiceImpl] - selectAll:null
    2017-03-30 08:52:17,366 [http-bio-8080-exec-4] WARN  [org.springframework.remoting.support.RemoteInvocationTraceInterceptor] - Processing of HessianServiceExporter remote call resulted in fatal exception: com.xinwei.process.service.DataCommBizService.selectAll
    java.lang.NullPointerException
        at com.xinwei.process.service.impl.DataCommBizServiceImpl.selectAll(DataCommBizServiceImpl.java:35)

    例子: http://www.cnblogs.com/langtianya/p/4981880.html
  • 相关阅读:
    Node.js v0.10.1 稳定版发布
    PHP 5.5.0 Alpha6 发布
    DataNucleus Access Platform 3.2 正式版发布
    Swipe 2.0 发布,移动端滑动 JS 库
    Kamailio 4.0 发布,开源的SIP服务器
    PeerJS 0.1.7:一个用于浏览器内P2P的WebRTC封装器
    Apache Libcloud 0.12.3 发布
    IE 10将加强对Flash的支持
    JBoss Portlet Bridge 3.2.0.Beta2 发布
    如何在遗留代码基础上开发
  • 原文地址:https://www.cnblogs.com/alamps/p/6644782.html
Copyright © 2011-2022 走看看