JAXB 异常:此上下文中未知的类 [英] JAXB Exception: Class not known to this context

查看:32
本文介绍了JAXB 异常:此上下文中未知的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用使用 CXF 构建的特定 Restful 服务方法时,出现以下错误,有人知道为什么以及如何解决吗?

When I call a particular restful service method, which is built using CXF, I get the following error, anyone know why and how to resolve it?

发生JAXBException:类com.octory.ws.dto.ProfileDto 或任何它的超类是已知的上下文...

JAXBException occurred : class com.octory.ws.dto.ProfileDto nor any of its super class is known to this context...

服务方式及相关DTO如下:

Following are the service method and relevant DTOs:

public class Service {
   public Response results() {
   Collection<ProfileDto> profilesDto = new ArrayList<ProfileDto>();
   ...
   SearchResultDto srd = new SearchResultDto();
   srd.setResultEntities(profilesDto); // Setting profilesDto collection as resultEntities
   srd.setResultSize(resultSize);
   return Response.ok(srd).build();
   }
}

SearchResultDto:

@XmlRootElement(name="searchResult")
public class SearchResultDto {
    private Collection resultEntities;
    private int resultSize;

    public SearchResultDto() { }

    @XmlElementWrapper(name="resultEntities")
    public Collection getResultEntities() {
        return resultEntities;
    }

    public void setResultEntities(Collection resultEntities) {
        this.resultEntities = resultEntities;
    }

    public int getResultSize() {
        return resultSize;
    }

    public void setResultSize(int resultSize) {
        this.resultSize = resultSize;
    }
}

ProfileD 到:

@XmlRootElement(name="profile")
public class ProfileDto {
    ...
    ...
    public ProfileDto() { }
    ...
}

推荐答案

SearchResultDto 中未引用您的 ProfileDto 类.尝试将 @XmlSeeAlso(ProfileDto.class) 添加到 SearchResultDto.

Your ProfileDto class is not referenced in SearchResultDto. Try adding @XmlSeeAlso(ProfileDto.class) to SearchResultDto.

这篇关于JAXB 异常:此上下文中未知的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆