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