As described in CORS preflight request fails due to a standard header if you send requests to OPTIONS
endpoints with the Origin
and Access-Control-Request-Method
headers set then they get intercepted by the Spring framework, and your method does not get executed. The accepted solution is the use @CrossOrigin
annotations to stop Spring returning a 403
. However, I am generating my API code with Swagger Codegen and so I just want to disable this and implement my OPTIONS
responses manually.
So can you disable the CORS interception in Spring?
As described in CORS preflight request fails due to a standard header if you send requests to OPTIONS endpoints with the Origin and Access-Control-Request-Method headers set then they get intercepted by the Spring framework, and your method does not get executed.
To code to set the CORS configuration globally in main Spring Boot application is given below. Now, you can create a Spring Boot web application that runs on 8080 port and your RESTful web service application that can run on the 9090 port.
No. You need to add @CrossOrigin annotation by yourself to get CORS Support in Spring.
For newer versions of spring boot:
@Configuration public class WebConfiguration implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**").allowedMethods("*"); } }
The Kotlin way
@Configuration class WebConfiguration : WebMvcConfigurer { override fun addCorsMappings(registry: CorsRegistry) { registry.addMapping("/**").allowedMethods("*") } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With