Skip to content

AlreadyBuiltException: This object has already been built #3916

@rwinch

Description

@rwinch

From #3825 (comment)

I had the same issue.

I was wiring a custom AuthenticationSuccessHandler into my security configuration that indirectly referenced a @service bean with an @Autowired reference to AuthenticationManager. After some thought, I'm surprised it worked - but no problems at all at runtime! Perhaps some sort of wiring order / race condition helped me out? However, while running the same vacuous test mentioned by @whittle, I encountered the dreaded AlreadyBuiltException.

Note that in a very stripped down version of my application I was debugging this issue with, I did receive a BeanCurrentlyInCreationException on AuthenticationManager but only during testing - not at runtime. Not exactly the same issue, but could be related behavior. See here: https://github.com/davidkey/SecurityTestErrorPOC.

My fix was to add @lazy to my AuthenticationSuccessHandler in my security configuration while I rethink my architecture a bit.

HTH.

Metadata

Metadata

Assignees

Labels

in: configAn issue in spring-security-configtype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions