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.
6689
6689
`@WebMvcTest` auto-configures the Spring MVC infrastructure and limits scanned beans to `@Controller`, `@ControllerAdvice`, `@JsonComponent`, `Converter`, `GenericConverter`, `Filter`, `HandlerInterceptor`, `WebMvcConfigurer`, and `HandlerMethodArgumentResolver`.
6690
-
Regular `@Component` beans are not scanned when using this annotation.
6690
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@WebMvcTest` annotation is used.
6691
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6691
6692
6692
6693
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>>.
6693
6694
@@ -6787,7 +6788,8 @@ TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you
6787
6788
==== Auto-configured Spring WebFlux Tests
6788
6789
To test that {spring-framework-docs}/web-reactive.html[Spring WebFlux] controllers are working as expected, you can use the `@WebFluxTest` annotation.
6789
6790
`@WebFluxTest` auto-configures the Spring WebFlux infrastructure and limits scanned beans to `@Controller`, `@ControllerAdvice`, `@JsonComponent`, `Converter`, `GenericConverter`, `WebFilter`, and `WebFluxConfigurer`.
6790
-
Regular `@Component` beans are not scanned when the `@WebFluxTest` annotation is used.
6791
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@WebFluxTest` annotation is used.
6792
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6791
6793
6792
6794
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>>.
6793
6795
@@ -6848,7 +6850,8 @@ TIP: Sometimes writing Spring WebFlux tests is not enough; Spring Boot can help
6848
6850
You can use the `@DataJpaTest` annotation to test JPA applications.
6849
6851
By default, it scans for `@Entity` classes and configures Spring Data JPA repositories.
6850
6852
If an embedded database is available on the classpath, it configures one as well.
6851
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6853
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataJpaTest` annotation is used.
6854
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6852
6855
6853
6856
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>>.
6854
6857
@@ -6922,7 +6925,8 @@ If, however, you prefer to run tests against a real database you can use the `@A
6922
6925
==== Auto-configured JDBC Tests
6923
6926
`@JdbcTest` is similar to `@DataJpaTest` but is for tests that only require a `DataSource` and do not use Spring Data JDBC.
6924
6927
By default, it configures an in-memory embedded database and a `JdbcTemplate`.
6925
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6928
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@JdbcTest` annotation is used.
6929
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6926
6930
6927
6931
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>>.
6928
6932
@@ -6953,7 +6957,8 @@ If you prefer your test to run against a real database, you can use the `@AutoCo
6953
6957
==== Auto-configured Data JDBC Tests
6954
6958
`@DataJdbcTest` is similar to `@JdbcTest` but is for tests that use Spring Data JDBC repositories.
6955
6959
By default, it configures an in-memory embedded database, a `JdbcTemplate`, and Spring Data JDBC repositories.
6956
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6960
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataJdbcTest` annotation is used.
6961
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6957
6962
6958
6963
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>>.
6959
6964
@@ -6972,12 +6977,12 @@ You can use `@JooqTest` in a similar fashion as `@JdbcTest` but for jOOQ-related
6972
6977
As jOOQ relies heavily on a Java-based schema that corresponds with the database schema, the existing `DataSource` is used.
6973
6978
If you want to replace it with an in-memory database, you can use `@AutoConfigureTestDatabase` to override those settings.
6974
6979
(For more about using jOOQ with Spring Boot, see "<<boot-features-jooq>>", earlier in this chapter.)
6975
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6980
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@JooqTest` annotation is used.
6981
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
6976
6982
6977
6983
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>>.
6978
6984
6979
6985
`@JooqTest` configures a `DSLContext`.
6980
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
6981
6986
The following example shows the `@JooqTest` annotation in use:
6982
6987
6983
6988
[source,java,indent=0]
@@ -7003,7 +7008,8 @@ If that is not what you want, you can disable transaction management for a test
7003
7008
==== Auto-configured Data MongoDB Tests
7004
7009
You can use `@DataMongoTest` to test MongoDB applications.
7005
7010
By default, it configures an in-memory embedded MongoDB (if available), configures a `MongoTemplate`, scans for `@Document` classes, and configures Spring Data MongoDB repositories.
7006
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7011
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataMongoTest` annotation is used.
7012
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7007
7013
(For more about using MongoDB with Spring Boot, see "<<boot-features-mongodb>>", earlier in this chapter.)
7008
7014
7009
7015
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>>.
@@ -7046,7 +7052,8 @@ If, however, you prefer to run tests against a real MongoDB server, you should e
7046
7052
==== Auto-configured Data Neo4j Tests
7047
7053
You can use `@DataNeo4jTest` to test Neo4j applications.
7048
7054
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.
7049
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7055
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataNeo4jTest` annotation is used.
7056
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7050
7057
(For more about using Neo4J with Spring Boot, see "<<boot-features-neo4j>>", earlier in this chapter.)
7051
7058
7052
7059
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>>.
@@ -7091,7 +7098,8 @@ If that is not what you want, you can disable transaction management for a test
7091
7098
==== Auto-configured Data Redis Tests
7092
7099
You can use `@DataRedisTest` to test Redis applications.
7093
7100
By default, it scans for `@RedisHash` classes and configures Spring Data Redis repositories.
7094
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7101
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataRedisTest` annotation is used.
7102
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7095
7103
(For more about using Redis with Spring Boot, see "<<boot-features-redis>>", earlier in this chapter.)
7096
7104
7097
7105
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>>.
@@ -7119,7 +7127,8 @@ The following example shows the `@DataRedisTest` annotation in use:
7119
7127
==== Auto-configured Data LDAP Tests
7120
7128
You can use `@DataLdapTest` to test LDAP applications.
7121
7129
By default, it configures an in-memory embedded LDAP (if available), configures an `LdapTemplate`, scans for `@Entry` classes, and configures Spring Data LDAP repositories.
7122
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7130
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@DataLdapTest` annotation is used.
7131
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7123
7132
(For more about using LDAP with Spring Boot, see "<<boot-features-ldap>>", earlier in this chapter.)
7124
7133
7125
7134
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>>.
@@ -7162,7 +7171,8 @@ If, however, you prefer to run tests against a real LDAP server, you should excl
7162
7171
==== Auto-configured REST Clients
7163
7172
You can use the `@RestClientTest` annotation to test REST clients.
7164
7173
By default, it auto-configures Jackson, GSON, and Jsonb support, configures a `RestTemplateBuilder`, and adds support for `MockRestServiceServer`.
7165
-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
7174
+
Regular `@Component` and `@ConfigurationProperties` beans are not scanned when the `@RestClientTest` annotation is used.
7175
+
`@EnableConfigurationProperties` can be used to include `@ConfigurationProperties` beans.
7166
7176
7167
7177
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