sourcecode

스프링 부트 액추에이터 상태 끝점을 사용자 지정 끝점으로 변경

copyscript 2023. 6. 28. 21:55
반응형

스프링 부트 액추에이터 상태 끝점을 사용자 지정 끝점으로 변경

스프링 부트 액추에이터 상태 끝점을 사용자 지정 끝점으로 변경할 수 있습니까?아래와 같은 것입니다.

http://localhost:8080/http/health

로.

http://localhost:8080/myapp/apphealth

이름만 바꾸고 작동기/상태의 응답은 원하지 않았습니다.가능합니까?

, 가능합니다.

액추에이터 끝점에 대한 경로를 사용자 지정하는 방법은 설명서의 이 섹션에서 정의합니다.

설명서에는 다음이 명시되어 있습니다.

엔드포인트를 다른 경로에 매핑하려는 경우 management.endpoints를 사용할 수 있습니다.web.path-interval 속성.

다음 예제에서는 /actuator/health를 /healthcheck에 재매핑합니다.

application.properties.

경영진, 경영진web.base-path=/

경영진, 경영진web.경로 추적.상태=상태 점검

그래서, 당신의 경우는 다음과 같습니다.

-- application.properties --
management.endpoints.web.base-path=/myapp
management.endpoints.web.path-mapping.health=apphealth

여기에 제시된 답변은 이미 이 질문에 대한 해결책을 제공했습니다.하지만, 저는 액추에이터 상태 끝점을 다른 목적으로 사용자 지정하는 데 어려움을 겪었고, 제 연구 결과를 다른 사람에게도 도움이 되도록 공유하고 싶습니다.아래의 모든 예는 다음을 위한 것입니다.Spring Boot 2.x.

기본 액추에이터 상태 끝점은 http://localhost:8080/actuator/health입니다.


옵션 1: 변경/actuator/health같은 사용자 지정 경로가 되는 것/actuator/test

다음을 추가합니다.application.properties파일

-- application.properties --
management.endpoints.web.path-mapping.health=test

경로: http://localhost:8080/http/test


옵션 2: 변경/actuator/health같은 사용자 지정 경로가 되는 것/myapp/test

다음을 추가합니다.application.properties파일

-- application.properties --
management.endpoints.web.base-path=/myapp
management.endpoints.web.path-mapping.health=test

경로: http://localhost:8080/myapp/test


옵션 3: 변경/actuator/health같은 사용자 지정 경로가 되는 것/health

다음을 추가합니다.application.properties파일

-- application.properties --
management.endpoints.web.base-path=/

경로: http://localhost:8080/health


옵션 4: 변경/actuator/health같은 사용자 지정 경로가 되는 것/test

다음을 추가합니다.application.properties파일

-- application.properties --
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=test

경로: http://localhost:8080/test


옵션 5: 포트 변경8080포트를 사용자 지정하는 방법8081

다음을 추가합니다.application.properties파일. 기본 응용 프로그램은 포트에서 실행됩니다.8080.

-- application.properties --
management.server.port=8081

경로: http://localhost:8081/http/health

언급URL : https://stackoverflow.com/questions/52654763/changing-spring-boot-actuator-health-end-point-to-a-custom-end-point

반응형