Enable CORS for Health Endpoint in Spring Boot Actuator

We want to include Cors for all GET requests in the /health endpoint provided by the spring drive.

We tried to add the next bean without success

 @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurerAdapter() { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/health").allowedMethods("GET"); } }; } 
+7
source share
2 answers

There are several properties that you can use to enable CORS for drive endpoints. For example, to allow GET requests from example.com in Spring Boot 1.x:

 endpoints.cors.allowed-origins=http://example.com endpoints.cors.allowed-methods=GET 

and for Spring Boot 2:

 management.endpoints.web.cors.allowed-origins=http://example.com management.endpoints.web.cors.allowed-methods=GET 
+13
source

Boot Spring 2:

You need to add permission options and enable headers as follows

 management.endpoints.web.cors.allowed-origins=* management.endpoints.web.cors.allowed-methods=OPTIONS, GET, POST management.endpoints.web.cors.allowed-headers=* 
0
source

All Articles