Spring Boot — print Hibernate SQL statements and parameters during integration tests without editing config files

Override of application properties from ENV vars

Spring supports override of application properties from environment variables.

As explained in the related section (v2.4.5), you basically just need to add an ENV var with the same name of the application property, upper case and with dot replaced with an underscore (as the majority of OS do not support dot as a variable name)

.. the configuration property spring.main.log-startup-info would be an environment variable named SPRING_MAIN_LOGSTARTUPINFO.

Settings to print hibernate statements

As also explained here, the settings to log the queries are

# application.properties

How to configure IntelliJ to print queries during integration tests

From the Run/Debug configuration. choose ‘Edit configuration templates…”, then in “Environment variables”. add the following

IntelliJ Run/Debug configuration
IntelliJ JUnit configuration

IMPORTANT: note that I voluntarily didn’t add the class name (last part of the setting) to the env variables. This is because of Spring internal mechanism, further details are given here.

Queries and parameters are now printed in the console.




Software Engineer @ London [https://www.linkedin.com/in/elvisciotti]

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Can I Upload That?

Kafka stream Semantics

Hard to solve system failures

Google Code Jam — Study Guide

Release Note —May 26, 2021

Divide and Conquer

SingularityNET Latest Ecosystem Updates: February, 2022

SingularityNET Ecosystem Roundup Blogpost Header Image

#DeFi #Initium #Launch

#Note My experience worked with vary data source

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Elvis Ciotti

Elvis Ciotti

Software Engineer @ London [https://www.linkedin.com/in/elvisciotti]

More from Medium

Object-relational Mapping Using JPA, Hibernate and Spring Data JPA.

Spring Boot Microservices — Part4 — OpenFeign

Authorisation with Spring Security — Part 1

Multi-module project with SpringBoot