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目录下创建一个文件名格式为Hessian-servlet.xml的配置文件
<!-- 业务类 --> <bean id="hessianService" class="com.cjm.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一样去操作了。原来实现一个webservice是可以这么简单 的。
人只要不失去方向,就不会失去自己