ABK*_*K07 36 java web-services cxf jaxb
当我调用使用CXF构建的特定的restful服务方法时,我收到以下错误,有人知道为什么以及如何解决它?
发生JAXBException:类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();
}
}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
ProfileDto:
@XmlRootElement(name="profile")
public class ProfileDto {
...
...
public ProfileDto() { }
...
}
Run Code Online (Sandbox Code Playgroud)
lex*_*ore 37
您的ProfileDto课程未被引用SearchResultDto.尝试添加@XmlSeeAlso(ProfileDto.class)到SearchResultDto.
use*_*141 30
我有这个错误,因为我在这行代码中注册了错误的类:
JAXBContext context = JAXBContext.newInstance(MyRootXmlClass.class);
Run Code Online (Sandbox Code Playgroud)
小智 6
我对弹簧靴有同样的问题。当我将包设置为编组器时它解决了。
@Bean
public Jaxb2Marshaller marshaller() throws Exception
{
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com.octory.ws.dto");
return marshaller;
}
@Bean
public WebServiceTemplate webServiceTemplate(final Jaxb2Marshaller marshaller)
{
WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);
return webServiceTemplate;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
93246 次 |
| 最近记录: |