问题
Just want to use HttpServletRequest
in my Rest service.
Get the follow error page when try to do GET request:
java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoader) previously initiated loading for a different type with name "javax/servlet/http/HttpServletRequest"
I use apache-karaf-4.1.5
as a container, apache-cxf
for JAX-RS implementation. And I marked javax.servlet-api
as provided
in pom.xml:
<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>
So.. any thoughts to avoid this error and makes this work properly ?
Thanks!
UPDATE mvn dependency:tree
output:
[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
来源:https://stackoverflow.com/questions/53309483/java-lang-linkageerror-while-using-httpservletrequest