JAXB 异常:此上下文中不知道的类
2022-09-01 00:54:12
当我调用使用 CXF 构建的特定 restful 服务方法时,我收到以下错误,有人知道为什么以及如何解决它吗?
JAXBException 发生: class com.octory.ws.dto.ProfileDto及其任何超类都是在这种背景下已知的......
以下是服务方式和相关 DTO:
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();
}
}
搜索结果:
@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;
}
}
ProfileDto:
@XmlRootElement(name="profile")
public class ProfileDto {
...
...
public ProfileDto() { }
...
}