Dropwizard中的两个异常映射器 [英] Two Exception Mappers in Dropwizard

查看:105
本文介绍了Dropwizard中的两个异常映射器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Dropwizard服务的父pom.在该服务中,我有一些异常映射器声明,例如:

@Provider
class ExceptionMapperForClassA {...}

现在在我的子pom中,我正在扩展此父服务,并且我想为 ClassA 创建New Exception映射器,我想从 ExceptionMapperForClassA 扩展它. /p>

我在Jersey文档中找不到任何信息,该文档描述了声明相同类的两个异常映射器时Jersey的行为.

https://jersey.java.net/documentation/latest/representations.html

实际上,问题是-如何重写某些异常映射器,并确保只有我的异常映射器会被调用?

解决方案

除非已更改,否则无法覆盖现有的异常映射器.我不记得我在哪里读过它,但是它说如果您注册了多个映射器,您将随机选择mapper作为响应.

我在这里的答案建议,您需要注销以前的例外mapper和and分配您的,但是在dropwizard 0.8之后也无法实现.除非0.9提供了解决方案,否则您应该着重于使父pom从外部获取参数并决定是否注册该ExceptionMapperForClassA.

I have parent pom with Dropwizard service. In that service I have some exception mapper declaration, for example:

@Provider
class ExceptionMapperForClassA {...}

Now in my child pom I'm extending this parent service and I want to create New Exception mapper for ClassA and I would like to extend it from ExceptionMapperForClassA.

I couldn't find any information in Jersey doc, which describes behaviour of Jersey when two exception mappers for same class are declared.

https://jersey.java.net/documentation/latest/representations.html

Actually, the question is - How to override some exception mapper and be sure that only my exception mapper will be called ?

解决方案

Unless that has changed, it's impossible to override an existing exception mapper. I don't remember where I had read it, but it said that you'd have randomly chosen mapper responding if you register more than one.

As my answer here suggests, you need to unregister the previous exception mapper and and assign yours but that also was made impossible after dropwizard 0.8. Unless 0.9 offers a solution for that, you should focus on making your parent-pom taking a parameter from outside and decide to whether to register that ExceptionMapperForClassA or not.

这篇关于Dropwizard中的两个异常映射器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆