`

class XXX nor any of its super class is known to this context.

    博客分类:
  • SOA
阅读更多

 用CXF传递复杂的数据类型,比如dto

@XmlType(name = "Customer")
@XmlAccessorType(XmlAccessType.FIELD)
public class Customer {
	private long id;
	private String name;
	private Date birthday;
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
}

 interface

 

@WebService
public interface TestService {
	String testString(String name);
	int testInt(int a, int b);
	List<String> testList(List<String> list);
	Customer testObject(Customer c);
}

 实现类

public Customer testObject(Customer c) {
		Customer ct = new Customer();
		ct.setId(2L);
		ct.setName("11");
		ct.setBirthday(new Date());
		return ct;
	}

 测试类

public void testObject() {
		try {
			Customer ct = new Customer();
			ct.setId(1L);
			ct.setName("33");
			ct.setBirthday(new Date());
			Object obj[] = client.invoke("testObject", ct);
			Customer cc = (Customer) obj[0]; 
			System.out.println(ct.getBirthday());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

 

当调用的时候,报错

Caused by: javax.xml.bind.JAXBException: class com.infodms.ws.dto.Customer nor any of its super class is known to this context.
	at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:594)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:648)
	... 41 more

 上网搜了一下,找不到合理的解释,把testObject的参数去掉,只留下返回值,报错

java.lang.ClassCastException: com.infodms.ws.test.Customer cannot be cast to com.infodms.ws.dto.Customer

 奇怪了Customer类明明是dto包中的类怎么cxf认为是test包中的类,原来接口和实现类都是test包中的类,cxf在object和xml转换的时候会默认在同一个包下面找dto,如果找不到则报错,把这个dto跟接口和实现类放到同一个包下面,问题解决。

 

 

我如果不想把dto和接口放到同一个包下面又该怎么办呢?我们需要在dto的上面定义它的namespace,注意这个字符串跟包名的顺序是相反的

@XmlType(name = "Customer", namespace = "dto.ws.infodms.com")

 问题解决。

 

 

 

分享到:
评论
1 楼 corleonelu 2011-12-20  
弄了一个下午了,终于可以吃饭了,

相关推荐

    spring-web-2.5.jar

    org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer.class org.springframework.web.context.support.ServletContextResource.class org.springframework.web.context.support....

    Unable to load class ‘javax.xml.bind.JAXBException‘(csdn).pdf

    Unable to load class ‘javax.xml.bind.JAXBException‘(csdn)

    SoapDiscovery.class.php

    SoapDiscovery.class.php

    servlet2.4doc

    The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object. addCookie(Cookie) - Method in interface javax.servlet.http.HttpServletResponse Adds the ...

    java的ejb.jar包

    javax.ejb.EntityContext.class javax.ejb.FinderException.class javax.ejb.Handle.class javax.ejb.HomeHandle.class javax.ejb.MessageDrivenBean.class javax.ejb.MessageDrivenContext.class javax.ejb....

    Introduction.To.Algorithms,.Second.Edition

    This is a large book, and your class will probably cover only a portion of its material. We have tried, however, to make this a book that will be useful to you now as a course textbook and also later ...

    javax.ejb.jar下载

    javax.ejb.EntityContext.class javax.ejb.FinderException.class javax.ejb.Handle.class javax.ejb.HomeHandle.class javax.ejb.IllegalLoopbackException.class javax.ejb.Init.class javax.ejb.Local.class ...

    数据结构作业Hash表

    Goals: This assignment is designed to reinforce the student's understanding of the use of hash tables as searchable containers. Outcomes: Students successfully completing this assignment would master...

    junit的jar包

    org.hamcrest.core.AnyOf.class org.hamcrest.core.DescribedAs.class org.hamcrest.core.Is.class org.hamcrest.core.IsAnything.class org.hamcrest.core.IsEqual.class org.hamcrest.core.IsInstanceOf.class org...

    javax.ejb.jar

    javax.ejb.EntityContext.class javax.ejb.FinderException.class javax.ejb.Handle.class javax.ejb.HomeHandle.class javax.ejb.IllegalLoopbackException.class javax.ejb.Init.class javax.ejb.Local.class ...

    javax.ejb.rar

    javax.ejb.EntityContext.class javax.ejb.FinderException.class javax.ejb.Handle.class javax.ejb.HomeHandle.class javax.ejb.IllegalLoopbackException.class javax.ejb.Init.class javax.ejb.Local.class ...

    mysql.class.zip_This Is It

    this is a simple mysql class . join it vahdat .

    谈谈Android里的Context的使用

    大家好,今天给大家分享一下Android里的Context的一些用法. 这里大致可以分为两种:一是传递Context参数,二是调用全局的Context. 其实我们应用启动的时候会启动Application这个类,这个类是在AndroidManifest.xml...

    Android ZXing1.6核心类库(core.jar)

    com.google.zxing.BarcodeFormat.class com.google.zxing.Binarizer.class com.google.zxing.BinaryBitmap.class com.google.zxing.ChecksumException.class com.google.zxing.DecodeHintType.class ...

    JSP Simple Examples

    printStackTrace is a method of the Throwable class. By using this method we can get more information about the error process if we print a stack trace from the exception. Runtime Errors Errors are ...

    韩顺平SqlHelper.class.php工具类 等学习资料

    SqlHelper.class.php MyMiniSmarty.class.php emManage.php FenyePage.class.php Emp.class.php EmpModel.class.php Message.class.php Message.class.php MessageModel.class.php ............... 由于...

    Senfore_DragDrop_v4.1

    1) Before you do anything else, read the "Known problems" section of this document. 2) Install the source into a directory of your choice. The files are installed into three directories: DragDrop ...

    C.Programming.The.Ultimate.Way.to.Learn.C.1500481114

    This is today’s best beginner’s guide to writing C programs–and to learning skills you can use with practically any language. Its simple, practical instructions will help you start creating useful,...

    vb-gsm测试软件代码

    Line 21: Class MSWinsockLib.Winsock of control WinsockPc was not a loaded control class. Line 60: Class MSCommLib.MSComm of control MSComm1 was not a loaded control class. Line 70: Class TabDlg.SSTab ...

    输入法示例程序

    This function gets the default window handle to the IME class. ImmGetDescription This function copies the description of the IME to the specified buffer. ImmGetGuideLine This function gets ...

Global site tag (gtag.js) - Google Analytics