programing

Spring Boot Actuator에서 "/health" 끝점에 대해 CORS 활성화

sourcejob 2023. 7. 18. 21:42
반응형

Spring Boot Actuator에서 "/health" 끝점에 대해 CORS 활성화

우리는 모두에게 CORS를 활성화하고 싶습니다.GET에의 요청./health엔드포인트는 스프링 부트 액추에이터에서 제공합니다.

다음 빈을 추가하려고 했지만 실패했습니다.

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

액추에이터의 엔드포인트에 대해 CORS를 활성화하는 데 사용할 수 있는 몇 가지 속성이 있습니다.예를 들어, 다음과 같이 허용GET로부터의 요청.example.comSpring Boot 1.x에서:

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

Spring Boot 2의 경우:

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

스프링 부트 2:

다음과 같이 허용 옵션 및 허용 헤더를 추가해야 합니다.

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

언급URL : https://stackoverflow.com/questions/37077487/enable-cors-for-health-endpoint-in-spring-boot-actuator

반응형