Skip to content

Commit ddc5250

Browse files
committed
Document @MockBean behavior during context refresh
Closes gh-16333
1 parent 47c6bf7 commit ddc5250

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6865,6 +6865,11 @@ implementation:
68656865
}
68666866
----
68676867

6868+
NOTE: `@MockBean` cannot be used to mock the behavior of a bean that's exercised during
6869+
application context refresh. By the time the test is executed, the application context refresh
6870+
has completed and it is too late to configure the mocked behavior. We recommend using a `@Bean`
6871+
method to create and configure the mock in this situation.
6872+
68686873
Additionally, you can use `@SpyBean` to wrap any existing bean with a Mockito `spy`. See
68696874
the {dc-spring-boot-test}/mock/mockito/SpyBean.{dc-ext}[Javadoc] for full details.
68706875

0 commit comments

Comments
 (0)