• 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
  • 相关阅读:
    SQL查询效率100w数据查询只要1秒
    超级实用且不花哨的js代码大全 (四) JavaScript[对象.属性]集锦
    Sql Server实用操作维护小技巧集合
    asp.net截取字符串方法
    自己整理的asp.net 缓存 相关资料
    【译】初识SSRS 通向报表服务的阶梯系列(一)
    【译】无处不在的数据 通向报表服务的阶梯系列(三)
    【译】SSRS基础 通向报表服务的阶梯系列(二)
    浅谈SQL Server中的事务日志(三)在简单恢复模式下日志的角色
    SQL Server中生成测试数据
  • 原文地址:https://www.cnblogs.com/alamps/p/6644782.html
Copyright © 2020-2023  润新知