使用dropwizard + jersey客户端时如何避免依赖冲突

Man*_*tel 7 java maven-2 dropwizard jersey-client

我有一个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>
Run Code Online (Sandbox Code Playgroud)

DropWizard依赖项是:

<dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-core</artifactId>
        <version>0.8.1</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

启动时的错误很长,总结如下

    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
    ...
Run Code Online (Sandbox Code Playgroud)

我猜DropWizard正在使用另一个冲突的依赖,所以我该如何处理呢?

提前致谢

Nat*_*tan 5

Dropwizard 0.8.x使用Jersey 2.x,这自然会与您的Jersey 1.x依赖项冲突。

我认为jersey-client只要您没有dropwizard-client依赖性就可以了,但是jersey-core在很多方面会与dropwizard的球衣发生冲突,而我认为您无法解决。而且我也认为您也不需要jersey-core发送电子邮件。

如果您确实需要球衣,请尝试使用Jersey 2.16,而不是dropwizard使用的版本。