Overview

Here's a demo unit test reproducing the issue: https://github.com/romainmoreau/spy-demo/blob/master/src/test/java/com/example/demo/DemoMockTest.java

The issue happens with Spring Boot 3.4.0-RC1, but it was working with Spring Boot 3.4.0-M3.

Here's the full stack trace: https://github.com/romainmoreau/spy-demo/actions/runs/11532983997/job/32105377666#step:4:2342

It works with Spring Boot 3.4.0-RC1 if Spring Framework is downgraded to 6.2.0-RC1.

Related Issues

  • 33602

  • 33803

Comment From: sbrannen

Thanks for reporting the issue.

The root cause is that AbstractBeanFactory.isSingleton() throws a BeanCreationException for a Spring Data JpaRepository.

We'll look into it!

Comment From: sbrannen

This has been addressed on main and tested against the provided sample project.

@romainmoreau, please try it out with 6.2.0-SNAPSHOT and let us know if that addresses your issues.

Thanks,

Sam

Comment From: romainmoreau

@sbrannen I tested 6.2.0-SNAPSHOT also with the demo project and with a real project with various uses of @MockitoSpyBean some of which were affected by this issue and this patch fixed both, thanks!

Comment From: sbrannen

@sbrannen I tested 6.2.0-SNAPSHOT also with the demo project and with a real project with various uses of @MockitoSpyBean some of which were affected by this issue and this patch fixed both, thanks!

Awesome! 🚀

Thanks so much for trying it out and letting us know it works!