Spring

[Spring] 쿼리문 콘솔창에서 쉽게 확인하는 법

퉁그리 2021. 11. 8. 16:08

jpa를 사용할 때 실제 디비에 전해지는 쿼리의 파라미터를 정확하게 알고싶을 때, 외부 라이브러리를 쓰면 좋다.

 

gavlyukovskiy/spring-boot-data-source-decorator: Spring Boot integration with p6spy, datasource-proxy, flexy-pool and spring-cloud-sleuth (github.com)

 

GitHub - gavlyukovskiy/spring-boot-data-source-decorator: Spring Boot integration with p6spy, datasource-proxy, flexy-pool and s

Spring Boot integration with p6spy, datasource-proxy, flexy-pool and spring-cloud-sleuth - GitHub - gavlyukovskiy/spring-boot-data-source-decorator: Spring Boot integration with p6spy, datasource-p...

github.com

 

해당 사이트를 가면 여러가지 외부 라이브러리가 나온다.

 

우선 가장 첫번째 라이브러리인 p6spy를 적용해본다.

 

implementation("com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.7.1")

현재 1.7.1버전까지 업데이트 되어있기 때문에 build.gradle의 dependencies에 이 문장 하나만 추가해주면 된다.

 

이 문장을 추가해주고 테스트를 돌려보면,

 

이렇게 쿼리의 파라미터를 찍어준다.

 

 

개발을 할 때는 꽤 유용할 수 있지만, 성능저하를 유발할 수 있으니, 실제 서비스에서는 성능비교를 꼭 해봐야된다고 한다.