最后, DispatcheServlet 自定义初始化程序是真正解决我的问题的类。由于我实现了 optionsController
,因此OPTIONS请求失败,这是错误的。
所以我删除了 optionsController ,仅在我的Rest Controller中为OPTIONS请求添加了 handle
方法,就解决了问题:
@CrossOrigin(origins = "*", maxAge = 3600)@RestController@RequestMapping("/users")public class Users { @RequestMapping( value = "/edit", method = RequestMethod.PUT) public ResponseEntity<?> create(@RequestBody User user){ .... .... } @RequestMapping( value = "/**", method = RequestMethod.OPTIONS ) public ResponseEntity handle() { return new ResponseEntity(HttpStatus.OK); }}


