使用HttpServletRequest时出现java.lang.LinkageError

时间:2018-11-14 22:10:05

标签: java rest servlets cxf apache-karaf

只想在我的Rest服务中使用HttpServletRequest。 尝试执行GET请求时,获取以下错误页面:

  

java.lang.LinkageError:违反加载程序约束:加载程序(org / apache / felix / framework / BundleWiringImpl $ BundleClassLoader的实例)先前已启动了名称为“ javax / servlet / http / HttpServletRequest”的其他类型的加载

我将apache-karaf-4.1.5用作容器,将apache-cxf用作JAX-RS实现。然后在pom.xml中将javax.servlet-api标记为provided

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxrs</artifactId>
    <version>3.1.7</version>
</dependency>

那么..有什么想法可以避免此错误并使其正常工作?

谢谢!

更新 mvn dependency:tree输出:

[INFO] +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.0:compile
[INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.9.0:compile
[INFO] |  \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.0:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.3.11.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.3.11.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.3.11.RELEASE:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  \- org.springframework:spring-tx:jar:4.3.11.RELEASE:compile
[INFO] +- net.sourceforge.jtds:jtds:jar:1.3.1:test
[INFO] +- commons-io:commons-io:jar:2.4:compile
[INFO] +- com.google.guava:guava:jar:19.0:compile
[INFO] +- org.apache.commons:commons-csv:jar:1.1:compile
[INFO] +- org.apache.commons:commons-email:jar:1.4:compile
[INFO] |  +- com.sun.mail:javax.mail:jar:1.5.2:compile
[INFO] |  \- javax.activation:activation:jar:1.1.1:compile
[INFO] +- joda-time:joda-time:jar:1.6:compile
[INFO] +- commons-dbutils:commons-dbutils:jar:1.5:compile
[INFO] +- com.thoughtworks.xstream:xstream:jar:1.3.1:compile
[INFO] |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.0:compile
[INFO] +- javax.ws.rs:javax.ws.rs-api:jar:2.0:compile
[INFO] +- org.apache.poi:poi-ooxml:jar:3.17:compile
[INFO] |  +- org.apache.poi:poi:jar:3.17:compile
[INFO] |  |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |  \- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] |  +- org.apache.poi:poi-ooxml-schemas:jar:3.17:compile
[INFO] |  |  \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO] |  |     \- stax:stax-api:jar:1.0.1:compile
[INFO] |  \- com.github.virtuald:curvesapi:jar:1.04:compile
[INFO] +- org.dom4j:dom4j:jar:2.0.1:compile
[INFO] |  \- jaxen:jaxen:jar:1.1.6:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:provided
[INFO] +- org.whitesource:maven-dependency-tree-parser:jar:1.0.5:compile
[INFO] |  \- commons-lang:commons-lang:jar:2.4:compile
[INFO] +- org.apache.cxf:cxf-rt-frontend-jaxrs:bundle:3.1.7:provided
[INFO] |  +- org.apache.cxf:cxf-core:jar:3.1.7:provided
[INFO] |  |  +- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:provided
[INFO] |  |  |  \- org.codehaus.woodstox:stax2-api:jar:3.1.4:provided
[INFO] |  |  \- org.apache.ws.xmlschema:xmlschema-core:jar:2.2.1:provided
[INFO] |  +- javax.annotation:javax.annotation-api:jar:1.2:provided
[INFO] |  \- org.apache.cxf:cxf-rt-transports-http:jar:3.1.7:provided
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.0:test
[INFO] |  \- log4j:log4j:jar:1.2.17:test
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] \- org.mockito:mockito-all:jar:1.10.19:test

0 个答案:

没有答案