Skip to content

Commit b53f54f

Browse files
committed
Add tip about using AopTestUtils.getTargetProxy with proxied spy beans
Closes gh-22281
1 parent 6232ece commit b53f54f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -6286,6 +6286,9 @@ NOTE: While Spring's test framework caches application contexts between tests an
62866286
TIP: If you are using `@SpyBean` to spy on a bean with `@Cacheable` methods that refer to parameters by name, your application must be compiled with `-parameters`.
62876287
This ensures that the parameter names are available to the caching infrastructure once the bean has been spied upon.
62886288

6289+
TIP: When you are using `@SpyBean` to spy on a bean that is proxied by Spring, you may need to remove Spring's proxy in some situations, for example when setting expectations using `given` or `when`.
6290+
Use `AopTestUtils.getTargetProxy(yourProxiedSpy)` to do so.
6291+
62896292

62906293

62916294
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-tests]]

0 commit comments

Comments
 (0)