• 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
  • 相关阅读:
    装饰器模块和面试题
    装饰器和推导式
    设计商城系统,主要提供两个功能:商品管理、会员管理。
    写代码:三级菜单
    写代码:循环打印names列表,把元素和索引值都打印出来。
    写代码: 编写登录接口
    写代码:假设一年期定期利率为3.25%,计算一下需要过多少年,一万元的一年定期存款连本带息能翻番?
    写代码:输入一年份,判断该年份是否是闰年并输出结果。
    写代码:制作趣味模板程序
    变量n1和n2是什么关系
  • 原文地址:https://www.cnblogs.com/alamps/p/6644782.html
Copyright © 2020-2023  润新知