Loading...
52

I have a Spring Boot backend running on localhost:8080 and a React frontend on localhost:3000.

When I try to make API calls from React, I get:
__CODEBLOCK0__

How do I properly configure CORS in Spring Boot to allow requests from my React app?

asked 1 week ago

Log in to add a comment.

1 Answer

38

Here are three ways to configure CORS in Spring Boot:

Method 1: Global CORS Configuration (Recommended)
__CODEBLOCK0

*Method 2: Controller-level @CrossOrigin
_CODE_BLOCK_1_

Method 3: CORS Filter (for security configs)
_CODE_BLOCK_2_

Production Setup:*
CODEBLOCK3__

answered 6 days ago
Log in to answer this question.
Question Stats
Asked: 1 week ago
Views: 1.5k
Active: 1 hour ago
Related Tags