在dropwizard中为REST Web服务配置URI前缀

use*_*572 4 uri dropwizard

我正在开发一个REST API使用dropwizard。在resource可以使用访问https://<host>:port/item/1。可以看出没有URI前缀。如果必须配置URI前缀,需要做什么。可以在yaml配置文件中进行配置吗?谢谢!

Sas*_*lam 6

是的,可以在YAML中配置URI前缀(也称为根路径)。您可以使用简单的服务器出厂配置。很简单,在YAML中添加这两行。我已经使用'api'作为前缀。您可以将其替换为所需的URI前缀。

server:
  rootPath: '/api/*'
Run Code Online (Sandbox Code Playgroud)

稍微复杂一些的服务器配置看起来像这样,

server:
  adminConnectors:
    -
      port: 18001
      type: http
  adminContextPath: /admin
  applicationConnectors:
    -
      port: 18000
      type: http
  rootPath: /api/*
  type: default
Run Code Online (Sandbox Code Playgroud)

您可以参考以下示例https://github.com/dropwizard/dropwizard/blob/master/dropwizard-example/example.yml以获取服务器和其他配置详细信息。

如果您刚刚开始使用dropwizard,那么也是一个好主意http://www.dropwizard.io/0.9.2/docs/getting-started.html