我已经使用axis2 1.3运行基于soap的Web服务。 这一天,我们计划使用Jersey 1.6开发RESTful Web服务。
我用axis2 1.3和Jersey 1.6创建了web应用程序(war文件)并尝试在jboss5.1.0上部署它。
启动jboss后,我看到了以下错误消息。
com.sun.jersey.api.container.ContainerException: Unable to create resource
at com.sun.jersey.server.impl.resource.SingletonFactory$Singleton.init(SingletonFactory.java:139)
at com.sun.jersey.server.impl.application.WebApplicationImpl$9.f(WebApplicationImpl.java:533)
at com.sun.jersey.server.impl.application.WebApplicationImpl$9.f(WebApplicationImpl.java:531)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.server.impl.application.WebApplicationImpl.getResourceComponentProvider(WebApplicationImpl.java:531)
.....
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:200)
at com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:182)
at com.sun.jersey.server.impl.resource.SingletonFactory$Singleton.init(SingletonFactory.java:137)
... 87 more
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "javax.xml.bind.JAXBElement.<init>(Ljavax/xml/namespace/QName;Ljava/lang/Class;Ljava/lang/Object;)V" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, com/sun/jersey/server/wadl/WadlGeneratorImpl, and the class loader (instance of <bootloader>) for resolved class, javax/xml/bind/JAXBElement, have different Class objects for the type javax/xml/namespace/QName used in the signature
at com.sun.jersey.server.wadl.WadlGeneratorImpl.createResponse(WadlGeneratorImpl.java:194)
at com.sun.jersey.server.wadl.WadlBuilder.generateResponse(WadlBuilder.java:397)
at com.sun.jersey.server.wadl.WadlBuilder.generateMethod(WadlBuilder.java:166)
at com.sun.jersey.server.wadl.WadlBuilder.generateResource(WadlBuilder.java:308)
at com.sun.jersey.server.wadl.WadlBuilder.generateResource(WadlBuilder.java:271)
at com.sun.jersey.server.wadl.WadlBuilder.generate(WadlBuilder.java:107)
at com.sun.jersey.server.impl.wadl.WadlApplicationContextImpl.getApplication(WadlApplicationContextImpl.java:76)
at com.sun.jersey.server.impl.wadl.WadlResource.<init>(WadlResource.java:76)
... 94 more
14:23:18,155 ERROR [[/oasapi]] Servlet /oasapi threw load() exception
java.lang.LinkageError: loader constraint violation: when resolving method "javax.xml.bind.JAXBElement.<init>(Ljavax/xml/namespace/QName;Ljava/lang/Class;Ljava/lang/Object;)V" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, com/sun/jersey/server/wadl/WadlGeneratorImpl, and the class loader (instance of <bootloader>) for resolved class, javax/xml/bind/JAXBElement, have different Class objects for the type javax/xml/namespace/QName used in the signature
at com.sun.jersey.server.wadl.WadlGeneratorImpl.createResponse(WadlGeneratorImpl.java:194)
at com.sun.jersey.server.wadl.WadlBuilder.generateResponse(WadlBuilder.java:397)
at com.sun.jersey.server.wadl.WadlBuilder.generateMethod(WadlBuilder.java:166)
.....
谁可以教我什么是问题以及如何解决这个问题?
由于
答案 0 :(得分:4)
您的环境中提供了两个版本的javax.xml.namespace.QName类:
答案 1 :(得分:1)
我认为你有jar文件依赖项的问题。如果您正在使用maven尝试找出哪些库存在冲突,我会使用maven的:〜$ mvn dependency:tree
这将输出一些文本行,如:
[INFO] [dependency:tree {execution: default-cli}]
[INFO] org.braman.app:jersey-rest-wadl:war:1.0-SNAPSHOT
[INFO] +- log4j:log4j:jar:1.2.12:provided
[INFO] +- com.sun.jersey:jersey-server:jar:1.8:compile
[INFO] | +- asm:asm:jar:3.1:compile
[INFO] | \- com.sun.jersey:jersey-core:jar:1.8:compile
[INFO] +- com.sun.jersey:jersey-json:jar:1.8:compile
[INFO] | +- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO] | +- org.codehaus.jackson:jackson-core-asl:jar:1.7.1:compile
[INFO] | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.7.1:compile
[INFO] | +- org.codehaus.jackson:jackson-jaxrs:jar:1.7.1:compile
[INFO] | \- org.codehaus.jackson:jackson-xc:jar:1.7.1:compile
[INFO] \- javax.servlet:servlet-api:jar:2.5:provided
从这个输出中我可以分析库的依赖关系。 顺便说一下,这是样本maven pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.braman.app</groupId>
<artifactId>jersey-rest-wadl</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Jersey Restful Service WADL Example</name>
<properties>
<junit.version>3.8.1</junit.version>
<log4j.version>1.2.12</log4j.version>
<jersey.version>1.8</jersey.version>
<servlet_api.version>2.5</servlet_api.version>
</properties>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</exclusion>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet_api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2</url>
<layout>default</layout>
</repository>
<repository>
<id>wadl-repository</id>
<name>WADL Maven Repository</name>
<url>https://wadl.dev.java.net/nonav/repository/</url>
</repository>
</repositories>
<build>
<finalName>jrw</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<jbossHome>/data/Work/servers/jboss/jboss-5.1.0.GA</jbossHome>
<serverName>default</serverName>
<fileName>target/jrw.war</fileName>
</configuration>
</plugin>
</plugins>
</build>
</project>
我希望它会对你有所帮助。
答案 2 :(得分:1)
我注意到Jersey 1.5(在JBoss 5中制作REST XML feed)这个问题,升级到Jersey 1.9解决了它。
答案 3 :(得分:1)
我有类似的问题。我发现泽西提供的jaxb库和jboss提供的库之间存在冲突。
以下是解决我问题的pom.xml
的相关部分。注意我在答案中使用jersey 1.9
作为@Jon状态。
...
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.9</version>
<exclusions>
<exclusion>
<artifactId>jaxb-api</artifactId>
<groupId>javax.xml.bind</groupId>
</exclusion>
<exclusion>
<artifactId>jaxb-impl</artifactId>
<groupId>com.sun.xml.bind</groupId>
</exclusion>
</exclusions>
</dependency>
...
JBoss 5.1.0
泽西岛1.9
答案 4 :(得分:0)
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.12</version>
<exclusions>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
</exclusions>
</dependency>