1、在web.xml中的配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/applicationContext.xml,
/WEB-INF/Hessian-servlet.xml
</param-value>
</context-param>
<servlet>
<servlet-name>Hessian</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Hessian</servlet-name>
<url-pattern>/hessian/*</url-pattern>
</servlet-mapping>
2.必須在WEB-INF目錄下創(chuàng)建一個文件名格式為Hessian-servlet.xml的配置文件
<!-- 業(yè)務類 -->
<bean id="hessianService" class="com.weijy.webservice.hessian.HessianServiceImpl"/>
<!-- 遠程服務 -->
<bean name="/hessianService" class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="hessianService"/>
<property name="serviceInterface">
<value>com.cjm.webservice.hessian.HessianService</value>
</property>
</bean>
3.客戶端調用
String url = "http://localhost:8888/spring2/hessian/hessianService";
HessianProxyFactory factory = new HessianProxyFactory();
HessianService hessianServer =
(HessianService)factory.create(HessianService.class, url);
String ret = hessianServer.sayHello("Raymond.chen");
//....................
若使用spring則可通過 HessianProxyFactoryBean在客戶端連接服務,在spring的配置中加入:
<bean id="hessianService " class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8888/spring2/hessian/hessianService"/>
<property name="serviceInterface" value="com.weijy.webservice.hessian.HessianService"/>
</bean>
加入以上的配置后,就可像使用其他的bean一樣去操作了。原來實現(xiàn)一個webservice是可以這么簡單的。



































//....................



