我的项目中有一些Rest端点,我从另一台服务器的客户端应用程序调用.我已经使用@CrossOrigin注释成功禁用了Cors,除了在Chrome上抛出以下错误的Delete方法之外,所有方法都正常工作:
XMLHttpRequest无法加载http:// localhost:8856 / robotpart / 1291542214 /兼容性.对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头.因此,不允许来源“http://127.0.0.1:8888”访问.响应具有HTTP状态代码403.
这是我的控制器:
@CrossOrigin(origins = "*")
@ExposesResourceFor(RobotPart.class)
public class RobotPartController {
//All endpoints are working except the Delete Mapping
@GetMapping("/robotpart")
public ResponseEntity> listAllParts() {
//..
}
@GetMapping("/robotpart/{id}")
public ResponseEntity getById(@PathVariable Integer id) {
//..
}
@GetMapping("/robotpart/{id}/compatibilities")
public ResponseEntity> getRobotCompatibilities(@PathVariable Integer id,
//..
}
@PostMapping("/robotpart")
public ResponseEntity getById(@RequestBody @Valid RobotPart newRobot) {
//..
@PutMapping("/robotpart/{id}")
public ResponseEntity modify(@PathVariable Integer id, @Valid @RequestBody RobotPart newRobot) {
//...
}
@DeleteMapping("/robotpart/{id}")
public ResponseEntity deleteById(@PathVariable Integer id) {
//...
}
}
有什么办法吗?