Skip to content

Commit e4691a4

Browse files
committed
Document that sliced tests don't scan @ConfigurationProperties beans
Closes gh-23210
1 parent ba7a103 commit e4691a4

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6393,7 +6393,8 @@ assertThat(json.write(message))
63936393
==== Auto-configured Spring MVC Tests
63946394
To test whether Spring MVC controllers are working as expected, use the `@WebMvcTest` annotation.
63956395
`@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.
63976398

63986399
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>>.
63996400

@@ -6493,7 +6494,8 @@ TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you
64936494
==== Auto-configured Spring WebFlux Tests
64946495
To test that {spring-framework-docs}/web-reactive.html[Spring WebFlux] controllers are working as expected, you can use the `@WebFluxTest` annotation.
64956496
`@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.
64976499

64986500
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>>.
64996501

@@ -6554,7 +6556,8 @@ TIP: Sometimes writing Spring WebFlux tests is not enough; Spring Boot can help
65546556
You can use the `@DataJpaTest` annotation to test JPA applications.
65556557
By default, it scans for `@Entity` classes and configures Spring Data JPA repositories.
65566558
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.
65586561

65596562
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>>.
65606563

@@ -6628,7 +6631,8 @@ If, however, you prefer to run tests against a real database you can use the `@A
66286631
==== Auto-configured JDBC Tests
66296632
`@JdbcTest` is similar to `@DataJpaTest` but is for tests that only require a `DataSource` and do not use Spring Data JDBC.
66306633
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.
66326636

66336637
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>>.
66346638

@@ -6659,7 +6663,8 @@ If you prefer your test to run against a real database, you can use the `@AutoCo
66596663
==== Auto-configured Data JDBC Tests
66606664
`@DataJdbcTest` is similar to `@JdbcTest` but is for tests that use Spring Data JDBC repositories.
66616665
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.
66636668

66646669
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>>.
66656670

@@ -6678,12 +6683,12 @@ You can use `@JooqTest` in a similar fashion as `@JdbcTest` but for jOOQ-related
66786683
As jOOQ relies heavily on a Java-based schema that corresponds with the database schema, the existing `DataSource` is used.
66796684
If you want to replace it with an in-memory database, you can use `@AutoConfigureTestDatabase` to override those settings.
66806685
(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.
66826688

66836689
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>>.
66846690

66856691
`@JooqTest` configures a `DSLContext`.
6686-
Regular `@Component` beans are not loaded into the `ApplicationContext`.
66876692
The following example shows the `@JooqTest` annotation in use:
66886693

66896694
[source,java,indent=0]
@@ -6709,7 +6714,8 @@ If that is not what you want, you can disable transaction management for a test
67096714
==== Auto-configured Data MongoDB Tests
67106715
You can use `@DataMongoTest` to test MongoDB applications.
67116716
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.
67136719
(For more about using MongoDB with Spring Boot, see "<<boot-features-mongodb>>", earlier in this chapter.)
67146720

67156721
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
67526758
==== Auto-configured Data Neo4j Tests
67536759
You can use `@DataNeo4jTest` to test Neo4j applications.
67546760
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.
67566763
(For more about using Neo4J with Spring Boot, see "<<boot-features-neo4j>>", earlier in this chapter.)
67576764

67586765
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
67976804
==== Auto-configured Data Redis Tests
67986805
You can use `@DataRedisTest` to test Redis applications.
67996806
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.
68016809
(For more about using Redis with Spring Boot, see "<<boot-features-redis>>", earlier in this chapter.)
68026810

68036811
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:
68256833
==== Auto-configured Data LDAP Tests
68266834
You can use `@DataLdapTest` to test LDAP applications.
68276835
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.
68296838
(For more about using LDAP with Spring Boot, see "<<boot-features-ldap>>", earlier in this chapter.)
68306839

68316840
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
68686877
==== Auto-configured REST Clients
68696878
You can use the `@RestClientTest` annotation to test REST clients.
68706879
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.
68726882

68736883
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>>.
68746884

0 commit comments

Comments
 (0)