我正在使用dropwizard开发一个REST API
。可以使用https://<host>:port/item/1
访问resource
。可以看出,没有URI
前缀。如果我必须配置URI
前缀,需要做什么。可以在yaml
配置文件中配置吗?谢谢!
是的,可以在 YAML 中配置 URI 前缀(即根路径(。您可以使用简单的服务器工厂配置。很简单,在 YAML 中添加这两行。我使用"api"作为前缀。您可以将其替换为所需的 URI 前缀。
server:
rootPath: '/api/*'
稍微复杂的服务器配置看起来像这样,
server:
adminConnectors:
-
port: 18001
type: http
adminContextPath: /admin
applicationConnectors:
-
port: 18000
type: http
rootPath: /api/*
type: default
您可以参考此示例 https://github.com/dropwizard/dropwizard/blob/master/dropwizard-example/example.yml 了解服务器和其他配置详细信息。
如果您刚刚开始使用dropwizard http://www.dropwizard.io/0.9.2/docs/getting-started.html,那么完成此操作也是一个好主意