spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.77k stars 38.16k forks source link

Bean Overrides for certain `FactoryBean` use cases no longer work #33800

Closed romainmoreau closed 1 month ago

romainmoreau commented 1 month ago

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

sbrannen commented 1 month ago

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!

sbrannen commented 1 month ago

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

romainmoreau commented 1 month ago

@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!

sbrannen commented 1 month ago

@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!