【问题标题】:Not able to find the Implementation Class for an Interface in Java在 Java 中找不到接口的实现类
【发布时间】:2014-10-09 17:29:13
【问题描述】:

我正在尝试修改此链接给出的 Openmrs 休息调用: https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/SessionController.java

它在代码中导入了一个spring框架org.springframework.web.context.request.WebRequest我无法跟踪 openmrs 存储库中实现此接口 WebRequest 的类。

openmrs repo 在这个链接上给出 -https://github.com/openmrs/openmrs-module-webservices.rest

到目前为止,我在 Openmrs wiki 上遇到了这样一条小线,上面写着- 我们所有的服务都是接口。这些服务的默认实现名为 *ServiceImpl.java。实现可以在 api 包的 impl 目录中找到。

谁能帮我弄清楚如何找到实现类?

【问题讨论】:

  • 为什么要实现该接口? Spring 提供了该类的实现,在使用该库时,理想情况下,您应该针对接口进行编程。

标签: java spring web-services rest openmrs


【解决方案1】:

这是Spring的接口。所以 Spring 创建并注入了它的一些实现。

import org.springframework.web.context.request.WebRequest;

如果您可以运行和调试代码,则在此控制器中放置断点,向此端点发出请求,然后您就可以找出实现类。

它将是这些类之一according documentation: DispatcherServletWebRequest、FacesWebRequest、NoSupportAsyncWebRequest、PortletWebRequest、ServletWebRequest、StandardServletAsyncWebRequest

通过快速查找,我在该存储库中找不到 servlet 配置。所以真的不知道它会是哪个类。 DispatcherServletWebRequest 是最常见的,因为 Spring MVC 主要与 Spring 的 DispatcherServlet 过滤器一起使用。

【讨论】:

    猜你喜欢
    • 2022-01-11
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    • 2010-09-30
    • 2012-11-29
    • 2018-03-14
    • 2013-04-17
    相关资源
    最近更新 更多