From 7286c33f536bdb62f958e53ad4672a2b97ab40fb Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 12 Apr 2021 14:14:36 +0200 Subject: [PATCH] Document default behaviour of DataJpaTest#showSql Closes gh-25843 --- .../src/docs/asciidoc/spring-boot-features.adoc | 3 +++ .../boot/test/autoconfigure/orm/jpa/DataJpaTest.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc index d2c86ca71f..07f1c32bd8 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc @@ -6912,6 +6912,9 @@ TIP: Sometimes writing Spring WebFlux tests is not enough; Spring Boot can help You can use the `@DataJpaTest` annotation to test JPA applications. By default, it scans for `@Entity` classes and configures Spring Data JPA repositories. If an embedded database is available on the classpath, it configures one as well. +SQL queries are logged by default by setting the `spring.jpa.show-sql` property to `true`. +This can be disabled using the `showSql()` attribute of the annotation. + Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataJpaTest` annotation is used. `@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans. diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java index 3133f5ca51..566969c900 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java @@ -53,6 +53,10 @@ import org.springframework.transaction.annotation.Transactional; * {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase} annotation can be used to * override these settings. *

+ * SQL queries are logged by default by setting the {@code spring.jpa.show-sql} property + * to {@code true}. This can be disabled using the {@link DataJpaTest#showSql() showSql} + * attribute. + *

* If you are looking to load your full application configuration, but use an embedded * database, you should consider {@link SpringBootTest @SpringBootTest} combined with * {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase} rather than this