You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From reading the docs I understand that I can add requirements to a bean so that it may not be available at runtime. What's not really clear is what happens if I inject a bean that has an unsatisfied requirement. Is the reference set to null? Is there an exception? If I want to say "give me this bean if it's available, but, not if it isn't" what am I supposed to do here? Presumably injecting lists of interfaces means it just won't appear in the list, but what if I don't need an extra interface and list? Maybe use Optional<BEAN>? The docs seem to think this is obvious but for people who haven't worked with Spring or similar frameworks, it isn't especially obvious.
The text was updated successfully, but these errors were encountered:
What's not really clear is what happens if I inject a bean that has an unsatisfied requirement. Is the reference set to null? Is there an exception?
A bean that doesn't match its requirements is never created. There is no such bean, and when trying to inject it elsewhere, you will get... NoSuchBeanException (pun intended 😜).
If I want to say "give me this bean if it's available, but, not if it isn't" what am I supposed to do here?
Wrap it in an Optional.
The docs seem to think this is obvious but for people who haven't worked with Spring or similar frameworks, it isn't especially obvious.
Would you please be so kind to send a PR to the exact parts of the docs where you miss this, given my previous answers?
Issue description
From reading the docs I understand that I can add requirements to a bean so that it may not be available at runtime. What's not really clear is what happens if I inject a bean that has an unsatisfied requirement. Is the reference set to null? Is there an exception? If I want to say "give me this bean if it's available, but, not if it isn't" what am I supposed to do here? Presumably injecting lists of interfaces means it just won't appear in the list, but what if I don't need an extra interface and list? Maybe use
Optional<BEAN>
? The docs seem to think this is obvious but for people who haven't worked with Spring or similar frameworks, it isn't especially obvious.The text was updated successfully, but these errors were encountered: