java 远程调用 hession

    技术2026-04-16  1

    服务器端的配置

    <bean name="/SEC/SecService" class="gov.mof.framework.bpo.ServiceExporter"> <property name="service" ref="fasp.sec.SecService"/> <property name="serviceInterface" value="gov.mof.fasp.sec.ISecService"/> </bean>

    客户端调用 spring 配置

     

    <!-- 调用 hession --> <bean id="mysecservice" class="org.springframework.remoting.caucho.HessianProxyFactoryBean"> <property name="serviceUrl"> <value>http://192.168.1.247:7001/web/remoting/SEC/SecService</value> </property> <property name="serviceInterface"> <value>gov.mof.fasp.sec.ISecService</value> </property> </bean>

    用到的代码 SpringBeanFactory

    package com.scmofit.untils; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.context.support.GenericApplicationContext; public class SpringBeanFactory { private static GenericApplicationContext context; static { if (context == null) { context = new GenericApplicationContext(); new XmlBeanDefinitionReader(context) .loadBeanDefinitions(new String[] {"classpath*:com/scmofit/configs/applicationContext*.xml" }); context.refresh(); } } private SpringBeanFactory() { } public static final Object getBean(String beanName) { return context.getBean(beanName); } }

    调用测试代码 Hession

    package com.scmofit.untils; import java.util.List; import gov.mof.fasp.AppException; public class Hession { public String getFinaceYear() throws AppException { gov.mof.fasp.sec.ISecService service=(gov.mof.fasp.sec.ISecService)SpringBeanFactory.getBean("mysecservice"); String a=service.getFinaceYear(); return a; } }

    jsp显示(用到 struts 2)

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body> <s:bean name="com.scmofit.untils.Hession" id="myhession"></s:bean> <s:property value="#myhession.getFinaceYear()"/> </body> </html>

     

    参考资料http://www.javaeye.com/topic/14887

     

    (在返回 引用类型 的时候 例如 List Map Bean可能出现  序列化 方面的异常)

     

    最新回复(0)