Home > Enterprise >  Override CORS policy in java springboot
Override CORS policy in java springboot

Time:11-07

I am trying to have my frontend server pull an http request from my backend server, but am getting the following error in my browser console:

Access to XMLHttpRequest at 'http://localhost:8080/run' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I know this is a security protocol, but is there an easy way to override this issue and allow for port 8080 (my backend) to return calls from port (3000)?

edit: I am using java springboot as my backend framework and React as my frontend framework

edit 2: I installed and used the Moesif Origin & CORS Changer extension and it works, I just would like to know if there is a more permanent workaround.

CodePudding user response:

A quick approach is to add @CrossOrigin (import is org.springframework.web.bind.annotation.CrossOrigin) to your Rest Controller(s).

  • Related