我正在使用Dropwizard 1.0.0-rc2并希望停止注册默认的异常映射器。所有文档都建议添加
server:
registerDefaultExceptionMappers: false
将阻止它们被注册,但是当我尝试将它们添加到配置文件中时,我得到一个ConfigurationParsingException,即server.registerDefaultExceptionMappers是一个无法识别的字段。
java.lang.RuntimeException: io.dropwizard.configuration.ConfigurationParsingException: application-config.yml has an error:
* Unrecognized field at: server.registerDefaultExceptionMappers
Did you mean?:
- adminConnectors
- applicationConnectors
- requestLog
- idleThreadTimeout
- adminContextPath
[19 more]
Caused by:
io.dropwizard.configuration.ConfigurationParsingException: application-config.yml has an error:
* Unrecognized field at: server.registerDefaultExceptionMappers
Did you mean?:
- adminConnectors
- applicationConnectors
- requestLog
- idleThreadTimeout
- adminContextPath
[19 more]
Caused by:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "registerDefaultExceptionMappers" (class io.dropwizard.server.DefaultServerFactory), not marked as ignorable (24 known properties: "umask", "gid", "idleThreadTimeout", "applicationContextPath", "adminContextPath", "adminMinThreads", "rootPath", "allowedMethods", "user", "uid", "nofileHardLimit", "adminMaxThreads", "adminConnectors", "applicationConnectors", "minThreads", "gzip", "maxQueuedRequests", "serverPush", "group", "shutdownGracePeriod", "maxThreads", "nofileSoftLimit", "startsAsRoot", "requestLog"])
at [Source: N/A; line: -1, column: -1] (through reference chain: com.company.manager.ApplicationConfiguration["server"]->io.dropwizard.server.DefaultServerFactory["registerDefaultExceptionMappers"])
我该如何指定,或者它是1.0.0-rc2中的错误?
答案 0 :(得分:1)
我刚做了一个小测试项目,看看它是否破损,它对我来说效果很好。我使用的是DW 1.0.0-rc2。
我的初级班:
public class Starter extends Application<Configuration> {
@Override
public void run(Configuration configuration, Environment environment) throws Exception {
environment.jersey().register(HelloWorldResource.class);
}
public static void main(String[] args) throws Exception {
new Starter().run("server", "/Users/artur/dev/repo/dw-test/src/main/resources/configuration.yaml");
}
}
我的资源:
@Path("/hello/world")
public class HelloWorldResource {
@GET
public String get() {
return "hello";
}
}
我的配置:
server:
registerDefaultExceptionMappers: false
applicationConnectors:
- type: http
port: 9085
这启动就好了。我调试了DefaultServerFactory,它按预期工作。
我不确定为什么这不适合你,但我建议尽可能简单地开始并重现问题,然后用可运行的代码更新你的问题进行测试。
你可能是自己打破了:
您尝试设置的字段位于子类中。也许你不小心重新配置了忽略子类类型的不同ObjectMapper?
此时我只是猜测,所以我会等待一些反馈。但是,要回答你的问题,上面是它的工作原理,似乎没有错误:)
我希望有所帮助,
阿图尔