0

我用 JAX-WS 创建了一个简单的 web 服务,但我期待一个令人讨厌的问题。

我的网络服务代码是这样的:

@WebService
public class UpdateList implements IUpdateList {

    public UpdateList() {
    }

    @Override
    public Collection<Long> getFrom(Long version) {
        System.out.println("test");
        return new ArrayList<Long>();
    }

}

我生成了客户端代码wsimport并为其创建了一个简单的主代码:

public class App {

    public static void main(String[] args) {
        System.out.println(new UpdateListService().getUpdateListPort().getFrom(183L));
    }
}

但是,当我运行它时,我得到了一个无法解释的类转换异常:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
    at $Proxy29.getFrom(Unknown Source)
    at com.test.App.main(App.java:8)
Caused by: java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.internal.bind.api.JAXBRIContext
    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.<clinit>(Unknown Source)
    ... 5 more

然后我才意识到这可能是一些依赖冲突,所以我运行了mvn dependency:tree,它很干净,我唯一的 deps 是 hibernate、guava、guice 和 jaxws-rt。(您可以在我的 web 服务示例中看到,它没有使用任何引用的依赖项,但我会尽快解决此问题)。

好吧,完整的清单,供客户使用:

+- com.google.guava:guava:jar:13.0:compile
+- com.google.inject:guice:jar:3.0:compile
|  +- javax.inject:javax.inject:jar:1:compile
|  \- aopalliance:aopalliance:jar:1.0:compile
+- log4j:log4j:jar:1.2.17:compile
+- junit:junit:jar:4.10:test
|  \- org.hamcrest:hamcrest-core:jar:1.1:test
+- com.sun.xml.bind:jaxb-impl:jar:2.2.6:compile
+- org.hsqldb:hsqldb:jar:2.2.8:test
+- com.google.inject.extensions:guice-persist:jar:3.0:compile
+- org.hibernate:hibernate-entitymanager:jar:4.1.6.Final:compile
|  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
|  +- org.hibernate:hibernate-core:jar:4.1.6.Final:compile
|  |  \- antlr:antlr:jar:2.7.7:compile
|  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
|  +- dom4j:dom4j:jar:1.6.1:compile
|  +- org.javassist:javassist:jar:3.15.0-GA:compile
|  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
+- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
+- mysql:mysql-connector-java:jar:5.1.21:compile
\- commons-lang:commons-lang:jar:2.6:compile

和服务:

 +- com.sun.xml.ws:jaxws-rt:jar:2.2.6-2:compile
 |  +- javax.xml.ws:jaxws-api:jar:2.2.8:compile
 |  |  +- javax.xml.bind:jaxb-api:jar:2.2.4:compile
 |  |  +- javax.xml.soap:saaj-api:jar:1.3.4:compile
 |  |  +- org.glassfish:javax.annotation:jar:3.1.1:runtime
 |  |  \- javax.jws:jsr181-api:jar:1.0-MR1:runtime
 |  +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3.18:compile
 |  +- com.sun.xml.stream.buffer:streambuffer:jar:1.4:compile
 |  |  +- javax.xml.stream:stax-api:jar:1.0-2:compile
 |  |  \- javax.activation:activation:jar:1.1:compile
 |  +- org.codehaus.woodstox:woodstox-core-asl:jar:4.1.2:compile
 |  +- org.codehaus.woodstox:stax2-api:jar:3.1.1:compile
 |  +- org.jvnet.mimepull:mimepull:jar:1.8:compile
 |  +- com.sun.xml.ws:policy:jar:2.3.1:compile
 |  |  +- com.sun.xml.txw2:txw2:jar:20110809:compile
 |  |  |  \- relaxngDatatype:relaxngDatatype:jar:20020414:compile
 |  |  \- com.sun.istack:istack-commons-runtime:jar:2.4:compile
 |  +- org.jvnet.staxex:stax-ex:jar:1.7:compile
 |  +- org.glassfish.gmbal:gmbal-api-only:jar:3.1.0-b001:compile
 |  |  \- org.glassfish.external:management-api:jar:3.0.0-b012:compile
 |  \- org.glassfish.ha:ha-api:jar:3.1.8:compile
 +- com.google.guava:guava:jar:13.0:compile
 +- com.google.inject:guice:jar:3.0:compile
 |  +- javax.inject:javax.inject:jar:1:compile
 |  \- aopalliance:aopalliance:jar:1.0:compile
 +- log4j:log4j:jar:1.2.17:compile
 +- junit:junit:jar:4.10:test
 |  \- org.hamcrest:hamcrest-core:jar:1.1:test
 +- com.sun.xml.bind:jaxb-impl:jar:2.2.6:compile
 +- org.hsqldb:hsqldb:jar:2.2.8:test
 +- com.google.inject.extensions:guice-persist:jar:3.0:compile
 +- org.hibernate:hibernate-entitymanager:jar:4.1.6.Final:compile
 |  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
 |  +- org.hibernate:hibernate-core:jar:4.1.6.Final:compile
 |  |  \- antlr:antlr:jar:2.7.7:compile
 |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
 |  +- dom4j:dom4j:jar:1.6.1:compile
 |  +- org.javassist:javassist:jar:3.15.0-GA:compile
 |  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
 +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
 +- mysql:mysql-connector-java:jar:5.1.21:compile
 \- commons-lang:commons-lang:jar:2.6:compile

我结束了这个想法,我的 jboss 中缺少一些配置或 jar 文件。我做了一些研究,但没有找到任何相关的东西。

有人已经通过了这个?有什么建议吗?谢谢

4

1 回答 1

1

看起来您正在捆绑一个 JAXP 实现,com.sun.xml.bind:jaxb-impl:jar:2.2.6:compile. 尝试将范围更改为<scope>provided</scope>. 对于com.sun.xml.ws:jaxws-rt:jar:2.2.6-2:compile.

事实上,大部分都应该提供。

于 2012-08-28T16:08:42.010 回答