Skip to content

@SpyBean causes BeanCurrentlyInCreationException when there are circular references #29639

@huangyoje

Description

@huangyoje

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions