Spring Data REST无法实例化PagedResourcesAssembler

时间:2016-09-28 14:07:01

标签: java spring spring-boot spring-data spring-data-rest

我'我试图公开一个应该使用PagedResourcesAssembler返回PagedResources响应的自定义控制器方法,但是在调用控制器方法时我最终会出现以下错误:

java.lang.NoSuchMethodException: org.springframework.data.web.PagedResourcesAssembler.<init>()
at java.lang.Class.getConstructor0(Unknown Source) ~[na:1.8.0_25]
at java.lang.Class.getDeclaredConstructor(Unknown Source) ~[na:1.8.0_25]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:102) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]

控制器

@RepositoryRestController
public class XDetailController {
@Autowired
private final XDetailRepositoryImpl xDetailRepo;

@RequestMapping(method = RequestMethod.GET, value = "/affiliates/{id}/xdetails") 
public @ResponseBody PagedResources<Resource<XDetail>> getAffiliateXDetails(@PathVariable Integer id, Pageable page, PagedResourcesAssembler<XDetail> assembler) {

    Page<XDetail> xDetails = xDetailRepo.findByPersonId(id, page);      
    PagedResources<Resource<XDetail>> resources = assembler.toResource(xDetails, linkTo(methodOn(XDetailController.class).getAffiliateXDetails(id, page, assembler)).withSelfRel());
    for(Resource<XDetail> resource : resources){
        resource.add(linkTo(methodOn(XDetailController.class).getXDetail(resource.getContent().getId())).withSelfRel());
    }                   
    return resources;
}

我的Application类中没有特殊配置,使用@SpringBootApplication注释

缺少一些配置或Spring bug?

更新

它在我的控制器上使用@RestController注释而不是@RepositoryRestController。但是,我希望它应该适用于@RepositoryRestController

0 个答案:

没有答案