Add core-di: constructor vs setter vs field injection and @Autowired candidate resolution on Boot 4.1
Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JoVmf2fWvcpoXndcDSwRf7
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# Five ways to say 'this may not exist', with zero and with two Notifier beans (Email registered before Sms)
|
||||
|
||||
|
||||
--- zero Notifier beans ---
|
||||
plain constructor param : FAILED NoSuchBeanDefinitionException
|
||||
Optional<Notifier> : isPresent=false
|
||||
@Nullable Notifier : value=null
|
||||
ObjectProvider.getIfAvailable() : null
|
||||
ObjectProvider.getIfUnique() : null
|
||||
ObjectProvider.getObject() : NoSuchBeanDefinitionException: No qualifying bean of type 'com.ankurm.coredi.injection.Notifier' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
|
||||
@Autowired(required=false) setter: value=null
|
||||
|
||||
--- two Notifier beans (Sms, Email), no @Primary ---
|
||||
ObjectProvider.getIfAvailable() : NoUniqueBeanDefinitionException: No qualifying bean of type 'com.ankurm.coredi.injection.Notifier' available: expected single matching bean but found 2: emailNotifier,smsNotifier
|
||||
ObjectProvider.getIfUnique() : null
|
||||
ObjectProvider.stream() classes : [EmailNotifier, SmsNotifier]
|
||||
ObjectProvider.orderedStream() : [SmsNotifier, EmailNotifier]
|
||||
Optional<Notifier> with two beans: FAILED NoUniqueBeanDefinitionException
|
||||
No qualifying bean of type 'com.ankurm.coredi.injection.Notifier' available: expected single matching bean but found 2: emailNotifier,smsNotifier
|
||||
Reference in New Issue
Block a user