SpringComponentRegistry - Handle missing Spring components adhering to the ComponentRegistry contract#4719
Merged
Conversation
…the ComponentRegistry contract
hatzlj
requested changes
Jul 8, 2026
hatzlj
left a comment
Contributor
There was a problem hiding this comment.
One finding that i would change and a few minor things
Translate BeanNotOfRequiredTypeException into ComponentNotFoundException for name-based lookups, and wrap the propagated NoUniqueBeanDefinitionException so it no longer leaks a raw Spring exception, keeping all lookup paths consistent with the ComponentRegistry contract. Also tag the newly added constructors with @SInCE 5.2.0 and strengthen the name-preserving test assertion so a regression to a null name would fail it.
ComponentRegistry contract
smcvb
approved these changes
Jul 8, 2026
smcvb
left a comment
Contributor
There was a problem hiding this comment.
One nit, otherwise this looks good to me 👍
The NoSuchBeanDefinitionException and BeanNotOfRequiredTypeException catch blocks translated to the same ComponentNotFoundException, so merge them into a single multi-catch. Kept as an explicit two-type catch rather than the shared BeansException supertype to avoid masking creation-time failures as "component not found".
ComponentRegistry contractComponentRegistry contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SpringComponentRegistry#getComponentnow catchesNoSuchBeanDefinitionExceptionfor theClass-only andClass+ name lookup paths and rethrows it as aComponentNotFoundException, matching theComponentRegistrycontract instead of letting the Spring-specific exception leak through.NoSuchBeanDefinitionExceptionas thecauseby adding a newComponentNotFoundException(type/typeReference, name, cause)constructor, and fixes theTypeReference+ name lookup path to include the requestednamein the thrown exception instead of always passingnull.Test plan
SpringAxonApplicationTestextended with cases assertingComponentNotFoundException(wrappingNoSuchBeanDefinitionException) is thrown for missing beans viagetComponent(Class),getComponent(Class, name), andgetComponent(TypeReference, name).