Spring Boot — print Hibernate SQL statements and parameters during integration tests without editing config files
IntelliJ JUnit test config to use ENV vars and enable hibernate logging
Override of application properties from ENV vars
Spring boot 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 namedSPRING_MAIN_LOGSTARTUPINFO
.
Settings to print hibernate statements
As also explained here, the settings to log the queries are
# application.properties
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
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
LOGGING_LEVEL_ORG_HIBERNATE=DEBUG;LOGGING_LEVEL_ORG_HIBERNATE_TYPE_DESCRIPTOR_SQL=TRACE
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.