spring boot could show sql even use JdbcTemplate directly

zhuguowei picture zhuguowei · Mar 8, 2016 · Viewed 9.2k times · Source

spring boot project, used JdbcTemplate, and want to show sql which is executed, the configuration is as below

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

but nothing output, it seems above configuration only support spring data jpa, So I'd like to know does exist some manner could show sql even used JdbcTemplate directly?

Answer

Stephane Nicoll picture Stephane Nicoll · Mar 8, 2016

There is a reason why the property is named spring.jpa something: it is to indicate you that it relates to JPA in some form.

If you're using JdbcTemplate, you're not using JPA hence that property can't have any effect. You can enable logging for the org.springframework.jdbc.core.JdbcTemplate class

logging.level.org.springframework.jdbc.core.JdbcTemplate=debug