53.9 어플리케이션 정보 by sh
응용 프로그램 정보는 ApplicationContext에 정의된 모든 InfoContributor빈에서 수집한 다양한 정보를 노출합니다. Spring Boot는 자동으로 구성된 InfoContributor 빈을 여러 개 포함하고 있으며 직접 작성할 수도 있습니다.
53.9.1 자동 구성된 InfoContributor 빈들
다음 InfoContributor빈은 적절한 경우 Spring Boot에 의해 자동 구성됩니다.
Name
Description
info키 아래의 Environment로부터 키를 노출합니다.
git.properties파일을 사용할 수있는 경우 git 정보를 표시합니다.
META-INF/build-info.properties파일을 사용할 수 있는 경우 빌드 정보를 표시합니다.
![[Tip]](https://wannaqueen.gitbook.io/spring5/~gitbook/image?url=https%3A%2F%2Fdocs.spring.io%2Fspring-boot%2Fdocs%2Fcurrent%2Freference%2Fhtmlsingle%2Fimages%2Ftip.png&width=300&dpr=4&quality=100&sign=e19e9545&sv=2)
management.info.defaults.enabled 속성을 설정하여 모두 비활성화 할 수 있습니다.
53.9.2 사용자 정의 어플리케이션 정보
info.*Spring 속성을 설정하여 info 끝점에 의해 노출 된 데이터를 사용자 정의 할 수 있습니다. info키 아래의 모든 Environment속성들은 자동으로 노출됩니다. 예를 들어, application.properties파일에 다음 설정을 추가 할 수 있습니다.
info.app.encoding=UTF-8
info.app.java.source=1.8
info.app.java.target=1.8![[Tip]](https://wannaqueen.gitbook.io/spring5/~gitbook/image?url=https%3A%2F%2Fdocs.spring.io%2Fspring-boot%2Fdocs%2Fcurrent%2Freference%2Fhtmlsingle%2Fimages%2Ftip.png&width=300&dpr=4&quality=100&sign=e19e9545&sv=2)
이러한 값을 하드 코딩하는 대신 빌드 시 info 속성을 확장 할 수도 있습니다. Maven을 사용한다고 가정하면 위의 예를 다음과 같이 다시 작성할 수 있습니다.
53.9.3 깃 커밋 정보
info 끝점의 또 다른 유용한 기능은 프로젝트가 빌드 되었을 때 git소스 코드 저장소의 상태에 대한 정보를 게시 할 수 있다는 것입니다. GitProperties빈을 사용할 수 있으면 git.branch, git.commit.id, and git.commit.time 속성이 노출됩니다.
![[Tip]](https://wannaqueen.gitbook.io/spring5/~gitbook/image?url=https%3A%2F%2Fdocs.spring.io%2Fspring-boot%2Fdocs%2Fcurrent%2Freference%2Fhtmlsingle%2Fimages%2Ftip.png&width=300&dpr=4&quality=100&sign=e19e9545&sv=2)
클래스 경로의 루트에서 git.properties 파일을 사용할 수 있으면 GitProperties빈은 자동으로 구성됩니다. 자세한 내용은 "Generate git information"을 참조하십시오.
전체 git 정보 (즉, git.properties의 전체 내용)를 표시하려면 다음과 같이 management.info.git.mode 속성을 사용하십시오.
management.info.git.mode=full53.9.4 빌드 정보
BuildProperties빈을 사용할 수있는 경우 info끝점은 빌드에 대한 정보를 게시 할 수도 있습니다. 이것은 META-INF/build-info.properties 파일이 classpath에서 사용 가능할 때 발생합니다.
53.9.5 사용자 정의 InfoContributors 작성하기
사용자 정의 응용 프로그램 정보를 제공하기 위해 InfoContributor인터페이스를 구현하는 Spring bean을 등록 할 수 있습니다.
다음 예제는 example 항목에 단일 값을 제공합니다.
import java.util.Collections;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;
@Component
public class ExampleInfoContributor implements InfoContributor {
@Override
public void contribute(Info.Builder builder) {
builder.withDetail("example",
Collections.singletonMap("key", "value"));
}
}info끝점을 보면, 다음 추가 항목이 포함된 응답을 볼 수 있습니다.
{
"example": {
"key" : "value"
}
}

Last updated
Was this helpful?