我有一个带有几个映射的REST控制器:
@RequestMapping(params = {"technicianId", "teamId"}, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<TeamTechnicianResource> findByTeamAndTechnician(@RequestParam(value = "teamId", required = true) Long teamId, @RequestParam(value = "technicianId", required = true) Long technicianId, UriComponentsBuilder builder) {
logger.debug("============>>> teamId: " + teamId + " technicianId: " + technicianId);
HttpHeaders responseHeaders = new HttpHeaders();
TeamTechnician foundTeamTechnician = teamTechnicianService.findByTeamAndTechnician(teamId, technicianId);
TeamTechnicianResource teamTechnicianResource = teamTechnicianResourceAssembler.toResource(foundTeamTechnician);
responseHeaders.setLocation(builder.path(UriMappingConstants.PATH_SEPARATOR + UriMappingConstants.TEAM_TECHNICIANS).queryParam("teamId", teamId).queryParam("technicianId", technicianId).buildAndExpand().toUri());
return new ResponseEntity<TeamTechnicianResource>(teamTechnicianResource, responseHeaders, HttpStatus.OK);
}
@RequestMapping(params = "technicianId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<PagedResources<TeamTechnicianResource>> findByTechnician(@RequestParam(value = "technicianId", required = true) Long technicianId, Pageable pageable, PagedResourcesAssembler<TeamTechnician> pagedResourcesAssembler, UriComponentsBuilder builder) {
HttpHeaders responseHeaders = new HttpHeaders();
Page<TeamTechnician> foundTeamTechnicians = teamTechnicianService.findByTechnician(technicianId, pageable);
responseHeaders.setLocation(builder.path(UriMappingConstants.PATH_SEPARATOR + UriMappingConstants.TEAM_TECHNICIANS).queryParam("technicianId", technicianId).queryParam("page", pageable.getPageNumber()).queryParam("size", pageable.getPageSize()).buildAndExpand().toUri());
Link selfLink = linkTo(methodOn(TeamTechnicianController.class).findByTechnician(technicianId, pageable, pagedResourcesAssembler, builder)).withRel("findByTechnician");
PagedResources<TeamTechnicianResource> teamTechnicianPagedResources = pagedResourcesAssembler.toResource(foundTeamTechnicians, teamTechnicianResourceAssembler, selfLink);
return new ResponseEntity<PagedResources<TeamTechnicianResource>>(teamTechnicianPagedResources, responseHeaders, HttpStatus.OK);
}
@RequestMapping(params = "teamId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<PagedResources<TeamTechnicianResource>> findByTeam(@RequestParam(value = "teamId", required = true) Long teamId, Pageable pageable, PagedResourcesAssembler<TeamTechnician> pagedResourcesAssembler, UriComponentsBuilder builder) {
HttpHeaders responseHeaders = new HttpHeaders();
Page<TeamTechnician> foundTeamTechnicians = teamTechnicianService.findByTeam(teamId, pageable);
responseHeaders.setLocation(builder.path(UriMappingConstants.PATH_SEPARATOR + UriMappingConstants.TEAM_TECHNICIANS).queryParam("teamId", teamId).queryParam("page", pageable.getPageNumber()).queryParam("size", pageable.getPageSize()).buildAndExpand().toUri());
Link selfLink = linkTo(methodOn(TeamTechnicianController.class).findByTeam(teamId, pageable, pagedResourcesAssembler, builder)).withRel("findByTeam");
PagedResources<TeamTechnicianResource> teamTechnicianPagedResources = pagedResourcesAssembler.toResource(foundTeamTechnicians, teamTechnicianResourceAssembler, selfLink);
return new ResponseEntity<PagedResources<TeamTechnicianResource>>(teamTechnicianPagedResources, responseHeaders, HttpStatus.OK);
}
只有在控制器中不存在带有teamId参数的第三个映射时,带有两个参数的第一个映射才会响应。
否则,例外是:
java.lang.NoSuchMethodError: org.springframework.http.MediaType.compareTo(Lorg/springframework/http/MediaType;)I
与technicianId的第二次映射总是在请求时响应。
使用teamId的第三个映射总是在请求时响应。
我在tomcat 7上使用Spring 4.0.7.RELEASE和Security 3.2.5.RELEASE。
有任何线索吗?
答案 0 :(得分:1)
正如JIRA问题所述,这不是框架问题,而是依赖管理问题。
在这个项目中,Spring Framework的多个(和不兼容的!)版本在类路径上:3.2.8和4.0.7。使用Spring Framework's "Bill Of Materials"是一种很好的方法来防止将来出现这些问题。