【发布时间】:2017-05-10 13:45:42
【问题描述】:
当我尝试在我的自定义控制器中自动装配 PersistentEntityResourceAssembler 时,它给了我以下错误。
Description:
Field resourceAssembler in api.controller.IslandController required a bean of type 'org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler' in your configuration.
这是我的控制器实现:
@RestController
public class IslandController {
@Autowired
private IslandRepository islandRepo;
@Autowired
private PagedResourcesAssembler pagedResourcesAssembler;
@Autowired
private PersistentEntityResourceAssembler resourceAssembler;
@RequestMapping(method = GET, value = "islands")
public ResponseEntity<?> getAllIslands(Pageable page) {
Page<Island> islandList = islandRepo.findAll(page);
return new ResponseEntity<>(pagedResourcesAssembler.toResource(islandList, resourceAssembler), HttpStatus.OK);
}
那么如何为 PersistentEntityResourceAssembler 定义一个 bean?
【问题讨论】:
标签: spring spring-mvc spring-boot spring-data-rest