Caused by: java.lang.NoSuchMethodException: javax.xml.bind.annotation.XmlElementRef.required()


在用java做webservice 的过程中,遇到的这个问题:

工具:myeclipse

jdk: 1.6

调用代码:

package com.client.demo;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;


public class Demo {
	public static void main(String args[]){
		JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
		Client client =  clientFactory.createClient("http://leyooo:8281/services/Staff?wsdl");
		try {
			//staff 人员接口
			int limit = 1;
			//如果有多个参数,直接在后面追加,参数对应的数据类型要正确
			//例:Object[] rsp = client.invoke("staffInfo",limit1,limit2,limit3);
			Object[] rsp = client.invoke("staffInfo",limit);
			System.out.println("return: " + rsp[0]);
		} catch (Exception e) {
			//e.printStackTrace();
			System.out.println(e.getMessage());
		}
	}
}

错误信息:

Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
	at $Proxy36.required(Unknown Source)
	at com.sun.tools.xjc.generator.bean.field.AbstractField.annotateReference(AbstractField.java:192)
	at com.sun.tools.xjc.generator.bean.field.AbstractField.annotate(AbstractField.java:161)
	at com.sun.tools.xjc.generator.bean.field.AbstractFieldWithVar.createField(AbstractFieldWithVar.java:80)
	at com.sun.tools.xjc.generator.bean.field.SingleField.(SingleField.java:94)
	at com.sun.tools.xjc.generator.bean.field.SingleField.(SingleField.java:81)
	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.tools.xjc.generator.bean.field.GenericFieldRenderer.generate(GenericFieldRenderer.java:69)
	at com.sun.tools.xjc.generator.bean.field.DefaultFieldRenderer.generate(DefaultFieldRenderer.java:82)
	at com.sun.tools.xjc.generator.bean.BeanGenerator.generateFieldDecl(BeanGenerator.java:774)
	at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassBody(BeanGenerator.java:555)
	at com.sun.tools.xjc.generator.bean.BeanGenerator.(BeanGenerator.java:258)
	at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:166)
	at com.sun.tools.xjc.model.Model.generateCode(Model.java:290)
	at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:283)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:54)
	at $Proxy26.bind(Unknown Source)
	at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:320)
	at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:240)
	at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:233)
	at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:188)
	at com.client.demo.Demo.main(Demo.java:10)
Caused by: java.lang.NoSuchMethodException: javax.xml.bind.annotation.XmlElementRef.required()
	at java.lang.Class.getDeclaredMethod(Class.java:1937)
	at com.sun.codemodel.TypedAnnotationWriter.invoke(TypedAnnotationWriter.java:112)
	... 29 more

问题:

     开始自己在eclipse下做的,测试均无问题,我的机器JDK是1.7版本,在与第三方人员进行联调测试时出现了以上的错误,他们使用的工具是myeclipse, JDK 1.6。myeclipse自带JDK版本也是1.6,这个问题很奇怪! google了下,看到很多解释说是其中几个jar包与jdk1.6不兼容的问题。

以下三个包:

jaxb-xjc-2.2.5.1.jar

jaxb-impl-2.2.5.1.jar

jaxb-api-2.2.5.jar

替换为:

jaxb-xjc-2.1.13.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.3.jar

替换完后,运行搞定!

由于自己不是专门做java开发的更多信息请访问:
http://cxf.547215.n5.nabble.com/Help-using-wsdl2java-script-td3284997.html

2.1版本jar包:
http://download.csdn.net/detail/u013706172/7231849
http://download.csdn.net/detail/u013706172/7231839
http://download.csdn.net/detail/u013706172/7231829


你可能感兴趣的:(Java)