我正在尝试使用 JAX RS 服务。我在我的 pom .xml 中添加了一些依赖项。这是pom。
<properties>
<jersey.version>1.19</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
<version>2.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.drill.exec</groupId>
<artifactId>drill-jdbc-all</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
当我添加此依赖项时<dependency>
<groupId>org.apache.drill.exec</groupId>
<artifactId>drill-jdbc-all</artifactId>
<version>1.1.0</version>
</dependency>
,它会因以下提到的异常而失败。我需要上面提到的 apache 演习的依赖。在删除和运行它工作顺利。
我得到的例外是:
java.lang.NoSuchMethodError: org.codehaus.jackson.map.AnnotationIntrospector.pair(Lorg/codehaus/jackson/map/AnnotationIn
trospector;Lorg/codehaus/jackson/map/AnnotationIntrospector;)Lorg/codehaus/jackson/map/AnnotationIntrospector;
at org.codehaus.jackson.jaxrs.MapperConfigurator._resolveIntrospectors(MapperConfigurator.java:155)
at org.codehaus.jackson.jaxrs.MapperConfigurator._setAnnotations(MapperConfigurator.java:133)
at org.codehaus.jackson.jaxrs.MapperConfigurator.getDefaultMapper(MapperConfigurator.java:70)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.locateMapper(JacksonJsonProvider.java:648)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:500)
at com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.writeTo(JacksonProviderProxy.java:160)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:302)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1510)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291).
有人可以帮忙解释一下为什么在添加特定依赖项时它会因上述异常而失败。
尝试运行 mvn 依赖树来检查 jar 中的冲突。
构建 JAXRS-JSON Maven Webapp 0.0.1-SNAPSHOT
------------------------------------------------------------------------
--- maven-dependency-plugin:2.8:tree (default-cli) @ JAXRS-JSON ---
com.java.codegeeks.example:JAXRS-JSON:war:0.0.1-SNAPSHOT
+- com.sun.jersey:jersey-servlet:jar:1.19:compile
| \- com.sun.jersey:jersey-server:jar:1.19:compile
+- com.sun.jersey:jersey-json:jar:1.19:compile
| +- org.codehaus.jettison:jettison:jar:1.1:compile
| +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
| | \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
| | +- javax.xml.stream:stax-api:jar:1.0-2:compile
| | \- javax.activation:activation:jar:1.1:compile
| +- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile
| +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:compile
| +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.2:compile
| +- org.codehaus.jackson:jackson-xc:jar:1.9.2:compile
| \- com.sun.jersey:jersey-core:jar:1.19:compile
| \- javax.ws.rs:jsr311-api:jar:1.1.1:compile
+- com.sun.jersey:jersey-client:jar:1.19:compile
+- junit:junit:jar:3.8.1:test
\- org.apache.drill.exec:drill-jdbc-all:jar:1.1.0:compile
------------------------------------------------------------------------
BUILD SUCCESS