java Dropwizard - 组织您的项目,理解术语等

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15977248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:31:20  来源:igfitidea点击:

Dropwizard - organizing your project, understanding terminology, etc

javahttprestdropwizard

提问by Sun

I am learning to use Dropwizard. I was able to follow the quickstart guide and run basic REST APIs.

我正在学习使用 Dropwizard。我能够按照快速入门指南运行基本的 REST API。

In this documentation, there is a section called "Organizing your project".

在本文档中,有一个名为“组织您的项目”的部分。

It recommends to organize your project in following parts: project-api, project-client, project-service.

它建议将您的项目组织成以下部分:project-api、project-client、project-service。

Here are my questions/queries:

这是我的问题/疑问:

  1. Please explain, in general terms, the difference between 'api', 'service' and 'client'.

  2. Is there an example which strictly follows the above convention using dropwizard?

  3. "...project-client should use those classes and an HTTP client to implement a full-fledged client for your service" --- since 'project-service' will have the REST APIs, then why do we need to use HTTP Client?

  1. 请概括地解释“api”、“服务”和“客户端”之间的区别。

  2. 是否有使用 dropwizard 严格遵循上述约定的示例?

  3. “...project-client 应该使用这些类和一个 HTTP 客户端来为您的服务实现一个成熟的客户端”---因为'project-service' 将拥有 REST API,那么我们为什么需要使用 HTTP 客户端?

Thanks!

谢谢!

回答by Sandy T

  1. Dropwizard recommends that you follow the below project structure:

    {project_name} (i.e parent with following modules)

    • {project_name}-api : should have all the value objects/POJO's that you are using in your project.
    • {project_name}-client : should contain client code used to get data from external rest service. Can be excluded, if you don't have any.
    • {project_name}-service : contains the remaining (service, configuration , resources, dao...etc).
  2. You may find thisexample helpful, even though client part is empty.

  3. As mentioned in the short description for client in point 1, if your project has any call to external rest services then related (HTTP)client code should go inside client module. Otherwise exclude the module itself.

  1. Dropwizard 建议您遵循以下项目结构:

    {project_name}(即具有以下模块的父级)

    • {project_name}-api :应该包含您在项目中使用的所有值对象/POJO。
    • {project_name}-client :应包含用于从外部休息服务获取数据的客户端代码。可以排除,如果你没有。
    • {project_name}-service :包含剩余的(服务、配置、资源、dao...等)。
  2. 您可能会发现示例很有帮助,即使客户端部分为空。

  3. 正如第 1 点中客户端的简短描述中提到的,如果您的项目有任何对外部休息服务的调用,那么相关的 (HTTP) 客户端代码应该放在客户端模块中。否则排除模块本身。

回答by DarkKnight

1) api- as by the name, it is the interface/contract which defines as Representations(Pojo -Json/Xml) in the project. These model define your API contracts, which could be shared with different project who are consuming your API.

1) api- 顾名思义,它是在项目中定义为 Representations(Pojo -Json/Xml) 的接口/合同。这些模型定义了您的 API 合同,这些合同可以与使用您的 API 的不同项目共享。

2) service- actual business logic and persistence. Representations needn't be same as your Entity objects (domain objects). This splits your domain and representations in a more clear way. Domain logic will no longer couple to your representation. Although this can cause significant duplication in terms of object structure.

2)服务——实际的业务逻辑和持久化。表示不必与您的实体对象(域对象)相同。这以更清晰的方式拆分您的域和表示。域逻辑将不再与您的表示耦合。尽管这可能会导致对象结构方面的大量重复。

Project Dependency - depends on "api", "client"

项目依赖 - 依赖于“api”、“client”

3) client- An Http Client wrapper to call other web services through HTTP calls using HttpClient or Jersey Client. Write (end-user) based testing for the contracts.

3)客户端- 一个 Http 客户端包装器,通过使用 HttpClient 或 Jersey 客户端的 HTTP 调用来调用其他 Web 服务。为合同编写基于(最终用户)的测试。

Project Dependency - depends on "api"

项目依赖 - 取决于“api”

Hope this helps.

希望这可以帮助。