When @SpyBean
is used on a field which is a circular reference, will raise a BeanCurrentlyInCreationException
.
Sample project that reproduces the problem: https://github.com/huangyoje/spybean-test
After some check, i think maybe SpyPostProcessor
does not following the spec of SmartInstantiationAwareBeanPostProcessor
.
The exposed object should be equivalent to the what postProcessBeforeInitialization / postProcessAfterInitialization would expose otherwise. Note that the object returned by this method will be used as bean reference unless the post-processor returns a different wrapper from said post-process callbacks. In other words: Those post-process callbacks may either eventually expose the same reference or alternatively return the raw bean instance from those subsequent callbacks (if the wrapper for the affected bean has been built for a call to this method already, it will be exposes as final bean reference by default).
getEarlyBeanReference, postProcessAfterInitialization
may return two different spy objects in current implementation.
Comment From: wilkinsona
I have a fix for this but I'd like to discuss with the team when, and even if, we want to make the change as it's not without risk.