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.
6858
6858
`@WebMvcTest` auto-configures the Spring MVC infrastructure and limits scanned beans to `@Controller`, `@ControllerAdvice`, `@JsonComponent`, `Converter`, `GenericConverter`, `Filter`, `HandlerInterceptor`, `WebMvcConfigurer`, and `HandlerMethodArgumentResolver`.
6859
-
Regular `@Component` beans are not scanned when using this annotation.
6859
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@WebMvcTest` annotation is used.
6860
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6860
6861
6861
6862
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>>.
6862
6863
@@ -6956,7 +6957,8 @@ TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you
6956
6957
==== Auto-configured Spring WebFlux Tests
6957
6958
To test that {spring-framework-docs}/web-reactive.html[Spring WebFlux] controllers are working as expected, you can use the `@WebFluxTest` annotation.
6958
6959
`@WebFluxTest` auto-configures the Spring WebFlux infrastructure and limits scanned beans to `@Controller`, `@ControllerAdvice`, `@JsonComponent`, `Converter`, `GenericConverter`, `WebFilter`, and `WebFluxConfigurer`.
6959
-
Regular `@Component` beans are not scanned when the `@WebFluxTest` annotation is used.
6960
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@WebFluxTest` annotation is used.
6961
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6960
6962
6961
6963
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>>.
6962
6964
@@ -7016,7 +7018,8 @@ TIP: Sometimes writing Spring WebFlux tests is not enough; Spring Boot can help
7016
7018
==== Auto-configured Data Cassandra Tests
7017
7019
You can use `@DataCassandraTest` to test Cassandra applications.
7018
7020
By default, it configures a `CassandraTemplate`, scans for `@Table` classes, and configures Spring Data Cassandra repositories.
7019
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7021
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataCassandraTest` annotation is used.
7022
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7020
7023
(For more about using Cassandra with Spring Boot, see "<<boot-features-cassandra>>", earlier in this chapter.)
7021
7024
7022
7025
TIP: A list of the auto-configuration settings that are enabled by `@DataCassandraTest` can be <<appendix-test-auto-configuration.adoc#test-auto-configuration,found in the appendix>>.
@@ -7045,7 +7048,8 @@ The following example shows a typical setup for using Cassandra tests in Spring
7045
7048
You can use the `@DataJpaTest` annotation to test JPA applications.
7046
7049
By default, it scans for `@Entity` classes and configures Spring Data JPA repositories.
7047
7050
If an embedded database is available on the classpath, it configures one as well.
7048
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7051
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataJpaTest` annotation is used.
7052
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7049
7053
7050
7054
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>>.
7051
7055
@@ -7119,7 +7123,8 @@ If, however, you prefer to run tests against a real database you can use the `@A
7119
7123
==== Auto-configured JDBC Tests
7120
7124
`@JdbcTest` is similar to `@DataJpaTest` but is for tests that only require a `DataSource` and do not use Spring Data JDBC.
7121
7125
By default, it configures an in-memory embedded database and a `JdbcTemplate`.
7122
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7126
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@JdbcTest` annotation is used.
7127
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7123
7128
7124
7129
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>>.
7125
7130
@@ -7150,7 +7155,8 @@ If you prefer your test to run against a real database, you can use the `@AutoCo
7150
7155
==== Auto-configured Data JDBC Tests
7151
7156
`@DataJdbcTest` is similar to `@JdbcTest` but is for tests that use Spring Data JDBC repositories.
7152
7157
By default, it configures an in-memory embedded database, a `JdbcTemplate`, and Spring Data JDBC repositories.
7153
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7158
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataJdbcTest` annotation is used.
7159
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7154
7160
7155
7161
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>>.
7156
7162
@@ -7169,12 +7175,12 @@ You can use `@JooqTest` in a similar fashion as `@JdbcTest` but for jOOQ-related
7169
7175
As jOOQ relies heavily on a Java-based schema that corresponds with the database schema, the existing `DataSource` is used.
7170
7176
If you want to replace it with an in-memory database, you can use `@AutoConfigureTestDatabase` to override those settings.
7171
7177
(For more about using jOOQ with Spring Boot, see "<<boot-features-jooq>>", earlier in this chapter.)
7172
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7178
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@JooqTest` annotation is used.
7179
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7173
7180
7174
7181
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>>.
7175
7182
7176
7183
`@JooqTest` configures a `DSLContext`.
7177
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7178
7184
The following example shows the `@JooqTest` annotation in use:
7179
7185
7180
7186
[source,java,indent=0]
@@ -7200,7 +7206,8 @@ If that is not what you want, you can disable transaction management for a test
7200
7206
==== Auto-configured Data MongoDB Tests
7201
7207
You can use `@DataMongoTest` to test MongoDB applications.
7202
7208
By default, it configures an in-memory embedded MongoDB (if available), configures a `MongoTemplate`, scans for `@Document` classes, and configures Spring Data MongoDB repositories.
7203
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7209
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataMongoTest` annotation is used.
7210
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7204
7211
(For more about using MongoDB with Spring Boot, see "<<boot-features-mongodb>>", earlier in this chapter.)
7205
7212
7206
7213
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>>.
@@ -7243,7 +7250,8 @@ If, however, you prefer to run tests against a real MongoDB server, you should e
7243
7250
==== Auto-configured Data Neo4j Tests
7244
7251
You can use `@DataNeo4jTest` to test Neo4j applications.
7245
7252
By default, it scans for `@Node` classes, and configures Spring Data Neo4j repositories.
7246
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7253
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataNeo4jTest` annotation is used.
7254
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7247
7255
(For more about using Neo4J with Spring Boot, see "<<boot-features-neo4j>>", earlier in this chapter.)
7248
7256
7249
7257
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>>.
@@ -7288,7 +7296,8 @@ If that is not what you want, you can disable transaction management for a test
7288
7296
==== Auto-configured Data Redis Tests
7289
7297
You can use `@DataRedisTest` to test Redis applications.
7290
7298
By default, it scans for `@RedisHash` classes and configures Spring Data Redis repositories.
7291
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7299
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataRedisTest` annotation is used.
7300
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7292
7301
(For more about using Redis with Spring Boot, see "<<boot-features-redis>>", earlier in this chapter.)
7293
7302
7294
7303
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>>.
@@ -7316,7 +7325,8 @@ The following example shows the `@DataRedisTest` annotation in use:
7316
7325
==== Auto-configured Data LDAP Tests
7317
7326
You can use `@DataLdapTest` to test LDAP applications.
7318
7327
By default, it configures an in-memory embedded LDAP (if available), configures an `LdapTemplate`, scans for `@Entry` classes, and configures Spring Data LDAP repositories.
7319
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7328
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataLdapTest` annotation is used.
7329
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7320
7330
(For more about using LDAP with Spring Boot, see "<<boot-features-ldap>>", earlier in this chapter.)
7321
7331
7322
7332
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>>.
@@ -7359,7 +7369,8 @@ If, however, you prefer to run tests against a real LDAP server, you should excl
7359
7369
==== Auto-configured REST Clients
7360
7370
You can use the `@RestClientTest` annotation to test REST clients.
7361
7371
By default, it auto-configures Jackson, GSON, and Jsonb support, configures a `RestTemplateBuilder`, and adds support for `MockRestServiceServer`.
7362
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7372
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@RestClientTest` annotation is used.
7373
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7363
7374
7364
7375
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