我正在与 Dropwizard sample project 合作从教程中,遇到了以下奇怪的问题:
使用以下服务器配置
server: type: default applicationConnectors: - type: http port: 8080
我的资源返回正确的响应。
当我将其更改为:
server: type: simple
我(从 Jetty 的日志中)看到它已正确注册和加载,但不起作用 - 如果我尝试相同的路径,我会在浏览器中看到 404 并
GET /wizard-resource/rs 200
在日志中。我试图在 yaml 配置中找到
simple
和default
之间的区别,但 Google 并没有对这个主题给出太多说明。
所以,这里有两个问题:
- 为什么使用简单的连接器,我在日志中得到 200,但在浏览器中得到 404?
- 简单连接器有什么用?什么时候它比默认连接器更好?
最佳答案
根据 Dropwizard Javadocs:
A single-connector implementation of {@link ServerFactory}, suitable for PaaS deployments (e.g., Heroku) where applications are limited to a single, runtime-defined port. A startup script can override the port via {@code -Ddw.server.connector.port=$PORT}.
The default implementation of {@link ServerFactory}, which allows for multiple sets of application and admin connectors, all running on separate ports. Admin connectors use a separate thread pool to keep the control and data planes separate(ish).
Configuration Reference documentation 中也提到了(尽管没有彻底)。 。
不知道为什么它记录为 200 而它是 404,这可能是一个错误;但您收到 404 的原因可能是因为简单服务器中的默认 applicationContextPath
配置是 /application
。所以如果你尝试
GET /application/wizard-resource/rs
它应该可以工作。
关于java - Dropwizard 配置 (yml) 行为异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29629835/