Java 一个简单的curl命令导致了这种荒谬

Java 一个简单的curl命令导致了这种荒谬,java,spring,spring-boot,spring-security,spring-data-rest,Java,Spring,Spring Boot,Spring Security,Spring Data Rest,在使用Spring数据REST和Spring安全性的Spring Boot 1.5.12应用程序中,当我通过curl发出delete时,一个琐碎的删除映射是错误的: curl -u 'admin:password' -X DELETE http://localhost:8080/api/shoes/20 服务器出现故障,出现Spring数据REST异常: ResourceNotFoundException: Resource not found! 当它试图解析可笑的URL时:

在使用Spring数据REST和Spring安全性的Spring Boot 1.5.12应用程序中,当我通过
curl
发出
delete
时,一个琐碎的删除映射是错误的:

    curl -u 'admin:password' -X DELETE http://localhost:8080/api/shoes/20
服务器出现故障,出现Spring数据REST异常:

    ResourceNotFoundException: Resource not found!
当它试图解析可笑的URL时:

    /api/shoes/api/shoes/20
看起来它是
/api/shoes
(资源)和
/api/shoes/20
(正在删除的项目)的组合。当然,这个URL不存在……但是这个URL来自哪里?端点很简单(使用Lombok):

它在日志中打印错误消息,后跟
ResourceNotFoundException
。该存储库同样通用:

@RepositoryRestResource(collectionResourceRel = "shoes", path = "shoes")
public interface ShoeRepository extends PagingAndSortingRepository<Shoe, Long> {
  // a set of query methods...
}
可能Spring Security试图在显然成功处理后对提交的URL(
/api/shoes/20
)进行处理,但不知何故有些处理不当。删除处理程序之后没有重定向


有什么不对劲吗?

啊!添加响应实体返回:

  @DeleteMapping("/shoes/{id}")
  public ResponseEntity<?> delete(@PathVariable("id") Long shoeId) {
    log.error("handle delete");
    return ResponseEntity.ok().build();
  }
@DeleteMapping(“/shoes/{id}”)
公共响应属性删除(@PathVariable(“id”)Long shoeId){
日志错误(“句柄删除”);
返回ResponseEntity.ok().build();
}

应该能更好地处理这个编程错误…

你能给我们看一下整个课程吗?这可能是rest控制器声明有问题。您的应用程序中是否有任何
重定向
?它也可能与来自spring数据的rest存储库冲突。你能给我们看一下存储库界面吗?愚蠢的问题,但你确定请求不会被处理两次吗?第一次,资源被删除,第二次它不存在,因此spring数据抛出exceptionRest存储库自动添加rest控制器并处理请求
  .antMatchers(HttpMethod.DELETE, "/api/shoes/**").hasRole("MANAGER")
  @DeleteMapping("/shoes/{id}")
  public ResponseEntity<?> delete(@PathVariable("id") Long shoeId) {
    log.error("handle delete");
    return ResponseEntity.ok().build();
  }