Files
spring-boot-demo/core-di/output/13-optional-and-objectprovider.txt

20 lines
1.3 KiB
Plaintext

# 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