我有一个DropWizard REST API编写并可以工作。其中一个资源端点实际上写了一封电子邮件,但是只要我添加以下依赖项,DropWizard就会在启动时失败
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.18.1</version>
</dependency>
DropWizard依赖项是:
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.8.1</version>
</dependency>
启动时的错误很长,总结如下
WARN [2015-05-01 20:06:08,887] org.glassfish.jersey.internal.Errors: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 2
java.lang.NullPointerException
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(AbstractJAXBProvider.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
....
MultiException stack 2 of 2
java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:395)
....
MultiException stack 3 of 3
java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
...
我猜测DropWizard正在使用另一个冲突的依赖,所以我该如何处理?
提前致谢
答案 0 :(得分:4)
Dropwizard 0.8.x使用Jersey 2.x,它自然与你的Jersey 1.x依赖项冲突。
我认为jersey-client
可能没问题,只要你没有dropwizard-client
依赖,但jersey-core
会在许多方面与dropwizard的球衣冲突,我认为你无法修复。而且我也认为您无论如何都需要jersey-core
发送电子邮件。
如果你确实需要球衣,请尝试使用Jersey 2.16,而不是使用的版本。
答案 1 :(得分:1)
我遇到了同样的问题(我使用的是DW 0.9.2,并且DW 0.7.2和Jersey 1.x都有不必要的传递依赖性)
解决方案非常简单:在为您带来这两个库系列的依赖项中,声明一个exclusion
并且它应该可以工作,例如,这就是我在Gradle中所做的:
compile("com.example.culprit:culprit:1.2.3") {
exclude group: 'io.dropwizard'
exclude group: 'com.sun.jersey'
}
Maven的语法非常相似(实际上更详细;-))
希望这有助于某人。