You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To test whether Spring MVC controllers are working as expected, use the `@WebMvcTest` annotation.
6395
6395
`@WebMvcTest` auto-configures the Spring MVC infrastructure and limits scanned beans to `@Controller`, `@ControllerAdvice`, `@JsonComponent`, `Converter`, `GenericConverter`, `Filter`, `HandlerInterceptor`, `WebMvcConfigurer`, and `HandlerMethodArgumentResolver`.
6396
-
Regular `@Component` beans are not scanned when using this annotation.
6396
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@WebMvcTest` annotation is used.
6397
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6397
6398
6398
6399
TIP: A list of the auto-configuration settings that are enabled by `@WebMvcTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
6399
6400
@@ -6493,7 +6494,8 @@ TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you
6493
6494
==== Auto-configured Spring WebFlux Tests
6494
6495
To test that {spring-framework-docs}/web-reactive.html[Spring WebFlux] controllers are working as expected, you can use the `@WebFluxTest` annotation.
6495
6496
`@WebFluxTest` auto-configures the Spring WebFlux infrastructure and limits scanned beans to `@Controller`, `@ControllerAdvice`, `@JsonComponent`, `Converter`, `GenericConverter`, `WebFilter`, and `WebFluxConfigurer`.
6496
-
Regular `@Component` beans are not scanned when the `@WebFluxTest` annotation is used.
6497
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@WebFluxTest` annotation is used.
6498
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6497
6499
6498
6500
TIP: A list of the auto-configurations that are enabled by `@WebFluxTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
6499
6501
@@ -6554,7 +6556,8 @@ TIP: Sometimes writing Spring WebFlux tests is not enough; Spring Boot can help
6554
6556
You can use the `@DataJpaTest` annotation to test JPA applications.
6555
6557
By default, it scans for `@Entity` classes and configures Spring Data JPA repositories.
6556
6558
If an embedded database is available on the classpath, it configures one as well.
6557
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6559
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataJpaTest` annotation is used.
6560
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6558
6561
6559
6562
TIP: A list of the auto-configuration settings that are enabled by `@DataJpaTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
6560
6563
@@ -6628,7 +6631,8 @@ If, however, you prefer to run tests against a real database you can use the `@A
6628
6631
==== Auto-configured JDBC Tests
6629
6632
`@JdbcTest` is similar to `@DataJpaTest` but is for tests that only require a `DataSource` and do not use Spring Data JDBC.
6630
6633
By default, it configures an in-memory embedded database and a `JdbcTemplate`.
6631
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6634
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@JdbcTest` annotation is used.
6635
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6632
6636
6633
6637
TIP: A list of the auto-configurations that are enabled by `@JdbcTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
6634
6638
@@ -6659,7 +6663,8 @@ If you prefer your test to run against a real database, you can use the `@AutoCo
6659
6663
==== Auto-configured Data JDBC Tests
6660
6664
`@DataJdbcTest` is similar to `@JdbcTest` but is for tests that use Spring Data JDBC repositories.
6661
6665
By default, it configures an in-memory embedded database, a `JdbcTemplate`, and Spring Data JDBC repositories.
6662
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6666
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataJdbcTest` annotation is used.
6667
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6663
6668
6664
6669
TIP: A list of the auto-configurations that are enabled by `@DataJdbcTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
6665
6670
@@ -6678,12 +6683,12 @@ You can use `@JooqTest` in a similar fashion as `@JdbcTest` but for jOOQ-related
6678
6683
As jOOQ relies heavily on a Java-based schema that corresponds with the database schema, the existing `DataSource` is used.
6679
6684
If you want to replace it with an in-memory database, you can use `@AutoConfigureTestDatabase` to override those settings.
6680
6685
(For more about using jOOQ with Spring Boot, see "<<boot-features-jooq>>", earlier in this chapter.)
6681
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6686
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@JooqTest` annotation is used.
6687
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6682
6688
6683
6689
TIP: A list of the auto-configurations that are enabled by `@JooqTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
6684
6690
6685
6691
`@JooqTest` configures a `DSLContext`.
6686
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6687
6692
The following example shows the `@JooqTest` annotation in use:
6688
6693
6689
6694
[source,java,indent=0]
@@ -6709,7 +6714,8 @@ If that is not what you want, you can disable transaction management for a test
6709
6714
==== Auto-configured Data MongoDB Tests
6710
6715
You can use `@DataMongoTest` to test MongoDB applications.
6711
6716
By default, it configures an in-memory embedded MongoDB (if available), configures a `MongoTemplate`, scans for `@Document` classes, and configures Spring Data MongoDB repositories.
6712
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6717
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataMongoTest` annotation is used.
6718
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6713
6719
(For more about using MongoDB with Spring Boot, see "<<boot-features-mongodb>>", earlier in this chapter.)
6714
6720
6715
6721
TIP: A list of the auto-configuration settings that are enabled by `@DataMongoTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
@@ -6752,7 +6758,8 @@ If, however, you prefer to run tests against a real MongoDB server, you should e
6752
6758
==== Auto-configured Data Neo4j Tests
6753
6759
You can use `@DataNeo4jTest` to test Neo4j applications.
6754
6760
By default, it uses an in-memory embedded Neo4j (if the embedded driver is available), scans for `@NodeEntity` classes, and configures Spring Data Neo4j repositories.
6755
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6761
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataNeo4jTest` annotation is used.
6762
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6756
6763
(For more about using Neo4J with Spring Boot, see "<<boot-features-neo4j>>", earlier in this chapter.)
6757
6764
6758
6765
TIP: A list of the auto-configuration settings that are enabled by `@DataNeo4jTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
@@ -6797,7 +6804,8 @@ If that is not what you want, you can disable transaction management for a test
6797
6804
==== Auto-configured Data Redis Tests
6798
6805
You can use `@DataRedisTest` to test Redis applications.
6799
6806
By default, it scans for `@RedisHash` classes and configures Spring Data Redis repositories.
6800
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6807
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataRedisTest` annotation is used.
6808
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6801
6809
(For more about using Redis with Spring Boot, see "<<boot-features-redis>>", earlier in this chapter.)
6802
6810
6803
6811
TIP: A list of the auto-configuration settings that are enabled by `@DataRedisTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
@@ -6825,7 +6833,8 @@ The following example shows the `@DataRedisTest` annotation in use:
6825
6833
==== Auto-configured Data LDAP Tests
6826
6834
You can use `@DataLdapTest` to test LDAP applications.
6827
6835
By default, it configures an in-memory embedded LDAP (if available), configures an `LdapTemplate`, scans for `@Entry` classes, and configures Spring Data LDAP repositories.
6828
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6836
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataLdapTest` annotation is used.
6837
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6829
6838
(For more about using LDAP with Spring Boot, see "<<boot-features-ldap>>", earlier in this chapter.)
6830
6839
6831
6840
TIP: A list of the auto-configuration settings that are enabled by `@DataLdapTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
@@ -6868,7 +6877,8 @@ If, however, you prefer to run tests against a real LDAP server, you should excl
6868
6877
==== Auto-configured REST Clients
6869
6878
You can use the `@RestClientTest` annotation to test REST clients.
6870
6879
By default, it auto-configures Jackson, GSON, and Jsonb support, configures a `RestTemplateBuilder`, and adds support for `MockRestServiceServer`.
6871
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6880
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@RestClientTest` annotation is used.
6881
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6872
6882
6873
6883
TIP: A list of the auto-configuration settings that are enabled by `@RestClientTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
0 commit comments