我正在使用spring-data-rest。
给定以下存储库:
@RepositoryRestResource
public interface MyRepository extends PagingAndSortingRepository<MyEntity, Long> {}
使用POST,PUT和PATCH方法时,
@RestResource(exported = false)
方法上的注释save()
使框架返回405 Method Not Allowed
错误。我的问题:在此存储库仍允许POST和PATCH的情况下,如何在PUT方法上返回405错误?
谢谢 !
最佳答案
@SWiggels
感谢您的答复 :)
您的解决方案对我不起作用...始终允许使用PUT。
对于其他人,我发现这很有效:
@BasePathAwareController
public class MyEntityController {
@RequestMapping(value = "/myentity/{id}", method = RequestMethod.PUT)
public ResponseEntity<?> preventsPut() {
return new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED);
}
}