I have created a stack overflow question regarding this enhancement here.

To summarize what was mentioned in that post above, I believe that we should be able to provide an interface class or an abstract class within the value of the @SpyBean annotation, and the framework should be intelligent enough to wrap the spring beans that extend the interface/abstract class with mockito spies. I was expecting this behaviour from the MockitoPostProcessor class.

Spring Boot Version: 2.2.8.RELEASE

Comment From: wilkinsona

When @SpyBean is used on a field, we need a single bean to spy so that the field's value can be injected. See https://github.com/spring-projects/spring-boot/issues/7621, https://github.com/spring-projects/spring-boot/issues/10655, https://github.com/spring-projects/spring-boot/pull/11066, and https://github.com/spring-projects/spring-boot/pull/11077 where support for using @Primary to identify which bean to spy when there are multiple candidates.

When @SpyBean is used on a class, we have more freedom and I think it would be possible to allow a single class to identify multiple beans to spy upon. Looking back at the 1.x code, things appear to have been closer to this before @Primary support was added, although I'm not sure that it worked as described here.

I'll flag this one for a team meeting so that we can discuss if this is something that we want to support.

Comment From: Domineer-Long

+1

Comment From: wilkinsona

@bclozel another one for Framework please to consider as a possible enhancement for @MockitoSpyBean.

Comment From: sbrannen

@simonbasle, how does this relate to the current implementation of @MockitoSpyBean in Spring Framework?

Comment From: simonbasle

@wilkinsona @sbrannen the bean override infrastructure in Framework is fields only

Comment From: wilkinsona

Thanks, @simonbasle. I assume that you're not considering expanding that support beyond fields so I'll close this one.