Nithin
Nithin

Reputation: 1477

Where and how to enable CORS on a Spring-Boot based WAR running on Tomcat?

I am running tomcat 9 on my VM and deploying Spring-Boot based WAR files built using gradle on it.

I keep getting CORS errors for the APIs running there.

I tried enabling the @CrossOrigin on Spring-boot but the error didn't seem to go away so I changed the web.xml file on my tomcat but still the CORS error keeps me from accessing my APIs.

What am I doing wrong and Where else should I enable the CORS setting and how?

Upvotes: 1

Views: 2154

Answers (1)

benjamin c
benjamin c

Reputation: 2338

You can enable cors support in spring boot application by adding @CrossOrigin annotation on controller method as follows,

@CrossOrigin(
    allowCredentials = "true",
    origins = "*", 
    allowedHeaders = "*", 
    methods = {RequestMethod.GET,RequestMethod.POST,RequestMethod.DELETE,RequestMethod.PUT}
)

Upvotes: 3

Related Questions