我正在开发 REST API
使用下拉向导。 resource
可以使用 https://<host>:port/item/1
访问.可以看出,没有 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
关于uri - 在 dropwizard 中为 REST web 服务配置 URI 前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35370353/