我使用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
生成了客户端代码并为其创建了一个简单的main:
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。 (你可以看到,在我的webservice示例中,它没有使用任何引用的依赖项,但是当我解决这个问题时,我会尽快完成。)
嗯,完整列表,对于客户:
+- 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文件。我做了一些研究,但没有发现任何相关的内容。
有人已经通过了这个吗?有什么建议吗?感谢
答案 0 :(得分: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
相同。
事实上,应该提供大部分内容。