我是Spring和Hessian的新手,以前从未使用过它们。
我想写一个小的Hello World程序,它清楚地显示了这个服务是如何工作的。
我使用Maven来列出项目细节和依赖项。
hessian的在线资源并不是完整的分步指南。
如果我能从一个写过hessian服务的人那里得到帮助,我将不胜感激
发布于 2011-01-21 12:40:22
实现Hessian-callable服务的步骤如下:
让我们来看一个例子。创建一个Java接口:
public interface EchoService {
String echoString(String value);
}编写一个实现此接口的Java类:
public class EchoServiceImpl implements EchoService {
public String echoString(String value) {
return value;
}
}在web.xml文件中,配置servlet:
<servlet>
<servlet-name>/EchoService</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>/EchoService</servlet-name>
<url-pattern>/remoting/EchoService</url-pattern>
</servlet-mapping>在Spring应用程序上下文中配置服务类的实例:
<bean id="echoService" class="com.example.echo.EchoServiceImpl"/>在Spring应用程序上下文中配置导出器。bean名称必须与servlet名称匹配。
<bean
name="/EchoService"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="echoService"/>
<property name="serviceInterface" value="com.example.echo.EchoService"/>
</bean>发布于 2011-02-03 17:57:47
客户端必须创建远程接口的代理。您可以简单地编写一个JUnit-Test:
HessianProxyFactory proxyFactory = new HessianProxyFactory();
proxyFactory.setHessian2Reply(false);
proxyFactory.setHessian2Request(false);
com.example.echo.EchoService service = proxyFactory.create(
com.example.echo.EchoService, "http://localhost:8080/<optional-context/>remoting/EchoService");
Assert.equals(service.echoString("test"), "test");https://stackoverflow.com/questions/4753852
复制相似问题