本文介绍了撰写粗麻布服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spring和Hessian的新手,以前从未使用过它们.

I am new to Spring and Hessian and never used them before.

我想编写一个小的Hello World程序,清楚地显示此服务的工作方式.

I want to write a small Hello World Program which clearly shows how this service works.

我正在使用Maven列出项目详细信息和依赖项.

I am using Maven for list project details and dependencies.

在线的粗麻布资源不是完整的分步指南.

The resources for hessian available online are not complete step-by-step guide.

如果能从曾经写过粗麻布服务的人那里得到帮助,我将不胜感激

would appreciate if I get help form someone who has worked writing hessian services

推荐答案

实现Hessian可调用服务的步骤是:

The steps for implementing a Hessian-callable service are:

  • 创建一个Java接口,定义要由客户端调用的方法.
  • 编写实现此接口的Java类.
  • 配置一个servlet来处理HTTP Hessian服务请求.
  • 配置 HessianServiceExporter 通过将服务调用委派给实现此接口的Java类来处理来自Servlet的Hessian服务请求.
  • Create a Java interface defining methods to be called by clients.
  • Write a Java class implementing this interface.
  • Configure a servlet to handle HTTP Hessian service requests.
  • Configure a HessianServiceExporter to handle Hessian service requests from the servlet by delegating service calls to the Java class implementing this interface.

我们来看一个例子.创建一个Java接口:

Let's go through an example. Create a Java interface:

public interface EchoService {
    String echoString(String value);
}

编写实现此接口的Java类:

Write a Java class implementing this interface:

public class EchoServiceImpl implements EchoService {
    public String echoString(String value) {
        return value;
    }
}

web.xml文件中,配置servlet:

In the web.xml file, configure a 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应用程序上下文中配置服务类的实例:

Configure an instance of the service class in the Spring application context:

<bean id="echoService" class="com.example.echo.EchoServiceImpl"/>

在Spring应用程序上下文中配置导出器. Bean名称必须与servlet名称匹配.

Configure the exporter in the Spring application context. The bean name must match the servlet name.

<bean
    name="/EchoService"
    class="org.springframework.remoting.caucho.HessianServiceExporter">
  <property name="service" ref="echoService"/>
  <property name="serviceInterface" value="com.example.echo.EchoService"/>
</bean>

这篇关于撰写粗麻布服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 21:21