Problems with Angular, CORS and Spring

后端 未结 3 1744
庸人自扰
庸人自扰 2020-12-18 16:57

I have a simple project based on @RestController and AngularJS. I can send GET requests from Angular to @RestController but i could not send POST request. I have an error in

3条回答
  •  被撕碎了的回忆
    2020-12-18 17:29

    In Spring 4.2 and further releases, there is a first class support for CORS out-of-the-box. The details can be found on this page.

    In the Spring classes annotated with RESTController, @CrossOrigin annotation can be used. Following code represents the same:

    @CrossOrigin(origins = "http://localhost:3000", maxAge = 3600)
    @RestController
    public class AngularController {
    }
    

    In the above code, localhost:3000 represents Angular app URL.

提交回复
热议问题