我正在使用Jersey 2.27在Java 1.8中实现API包装器。当我运行Invocation.Builder.get()时,出现以下错误:
Exception in thread "main" java.lang.IllegalStateException: InjectionManagerFactory not found.
at org.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManagerFactory$0(Injections.java:98)
...
按照指南here,我使用以下依赖项更新了Maven pom.xml文件:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.27</version>
</dependency>
现在,当我使用Maven进行编译时,会收到以下警告:
[WARNING] javax.inject-1.jar, javax.inject-2.5.0-b42.jar define 6 overlappping classes:
[WARNING] - javax.inject.Inject
[WARNING] - javax.inject.Singleton
[WARNING] - javax.inject.Scope
[WARNING] - javax.inject.Named
[WARNING] - javax.inject.Provider
[WARNING] - javax.inject.Qualifier
[WARNING] maven-shade-plugin has detected that some .class files
[WARNING] are present in two or more JARs. When this happens, only
[WARNING] one single version of the class is copied in the uberjar.
[WARNING] Usually this is not harmful and you can skeep these
[WARNING] warnings, otherwise try to manually exclude artifacts
[WARNING] based on mvn dependency:tree -Ddetail=true and the above
[WARNING] output
[WARNING] See http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin
从mvn dependency:tree
中,我可以看到上面显示的两个依赖关系导致了此冲突(我突出显示了有问题的行):
[INFO] +- org.glassfish.jersey.core:jersey-client:jar:2.27:compile
[INFO] | +- javax.ws.rs:javax.ws.rs-api:jar:2.1:compile
[INFO] | +- org.glassfish.jersey.core:jersey-common:jar:2.27:compile
[INFO] | | +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
>> [INFO] | \- org.glassfish.hk2.external:javax.inject:jar:2.5.0-b42:compile
[INFO] +- org.glassfish.jersey.inject:jersey-hk2:jar:2.27:compile
[INFO] | \- org.glassfish.hk2:hk2-locator:jar:2.5.0-b42:compile
[INFO] | +- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b42:compile
[INFO] | +- org.glassfish.hk2:hk2-api:jar:2.5.0-b42:compile
>> [INFO] | | \- javax.inject:javax.inject:jar:1:compile
[INFO] | +- org.glassfish.hk2:hk2-utils:jar:2.5.0-b42:compile
[INFO] | \- org.javassist:javassist:jar:3.22.0-CR2:compile
为什么在理论上应该一起更新这两个依赖项,从而导致此冲突?