`

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....

    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....

    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 ...

    谈谈Android里的Context的使用

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

    class.phpmailer.php

    结合`class.phpmailer.php`、`class.smtp.php`和`class.pop3.php`,我们可以构建出稳定的邮件系统,满足各种邮件应用场景的需求。对于初学者而言,理解并掌握PHPMailer的使用方法,将极大地提升其在PHP邮件处理方面...

    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,...

    输入法示例程序

    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 ...

    Smtp.class.php

    发送邮件时需要的类库文件,测试支持qq邮箱、163邮箱

    C.Programming.Step.By.Step.Beginners.To.Experts.Edition.B011EXMV7Q

    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,...

    org.apache.commons.lang jar包下载(commons-lang3-3.1.jar)

    org.apache.commons.lang.ClassUtils.class org.apache.commons.lang.Entities$ArrayEntityMap.class org.apache.commons.lang.Entities$BinaryEntityMap.class org.apache.commons.lang.Entities$EntityMap....

    Google C++ Style Guide(Google C++编程规范)高清PDF

    The goal of this guide is to manage this complexity by describing in detail the dos and don'ts of writing C++ code. These rules exist to keep the code base manageable while still allowing coders to ...

    MICROSOFT FOUNDATION CLASS LIBRARY

    This is a listing of all of the Microsoft Windows resources that the program uses. It includes the icons, bitmaps, and cursors that are stored in the RES subdirectory. This file can be directly ...

    class-of-builtins.rar_class

    在这个名为"class-of-builtins.rar_class"的压缩包里,包含的两个文件——10.1.5-1.js和class-of-builtins.js,很可能是关于JavaScript中的内置类以及自定义类的示例或教程。 1. **JavaScript 中的类(Class)** ...

Global site tag (gtag.js) - Google Analytics