编写粗麻布服务
我对 Spring 和 Hessian 很陌生,以前从未使用过它们。
我想编写一个小型的 Hello World 程序,它清楚地展示了该服务的工作原理。
我使用 Maven 来列出项目详细信息和依赖项。
在线提供的粗麻布资源并不是完整的分步指南。
如果我能得到曾经编写粗麻布服务的人的帮助,我将不胜感激
I am new to Spring and Hessian and never used them before.
I want to write a small Hello World Program which clearly shows how this service works.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实现 Hessian 可调用服务的步骤是:
让我们看一个例子。创建 Java 接口:
编写实现此接口的 Java 类:
在
web.xml
文件中,配置 servlet:在 Spring 应用程序上下文中配置服务类的实例:
在 Spring 中配置导出器应用程序上下文。 bean 名称必须与 servlet 名称匹配。
The steps for implementing a Hessian-callable service are:
Let's go through an example. Create a Java interface:
Write a Java class implementing this interface:
In the
web.xml
file, configure a servlet:Configure an instance of the service class in the Spring application context:
Configure the exporter in the Spring application context. The bean name must match the servlet name.
客户端必须创建远程接口的代理。您可以简单地编写一个 JUnit 测试:
The client has to create a proxy of the remote interface. You could simply write a JUnit-Test:
这个问题很古老,投票最多的答案已过时:Spring 的
HessianServiceExporter
在 Spring 5.3 中已弃用,并在 Spring 6 中删除。目前实现 Hessian 可调用服务的步骤是:
创建一个Java接口定义了客户端调用的方法。
编写一个实现此接口的 Java 类。
扩展
HessianServlet
以实现相同的接口,并将业务逻辑委托给在步骤 #2 中创建的 Java 类(可以直接在 servlet 中实现此逻辑,但不推荐)。使用Spring的
ServletRegistrationBean
来启用servlet。hessian-demo 提供了 Spring Boot 应用程序中基于 Hessian 的 Web 服务的工作示例,无需
HessianServiceExporter
。您甚至可以使用基于 Jakarta 的 Spring Boot 3。The question is very old and the most voted answer became obsolete: Spring's
HessianServiceExporter
was deprecated in Spring 5.3 and removed in Spring 6.Currently the steps for implementing a Hessian-callable service are:
Create a Java interface defining methods to be called by clients.
Write a Java class implementing this interface.
Extend
HessianServlet
to implement the same interface and delegate the business logic to the Java class created at step #2 (implementing this logic directly in the servlet is possible but not recommended).Use Spring's
ServletRegistrationBean
to enable the servlet.hessian-demo provides a working example of a Hessian-based web service in a Spring Boot application without
HessianServiceExporter
. You can even use the Jakarta-based Spring Boot 3.