Skip to content

Commit

Permalink
Update conditionalBeans.adoc to clarify how to depend on a conditiona…
Browse files Browse the repository at this point in the history
…l bean

Fixes micronaut-projects#10757
  • Loading branch information
mikehearn committed Apr 24, 2024
1 parent 87a1dbc commit f2cfa08
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/docs/guide/ioc/conditionalBeans.adoc
@@ -1,6 +1,6 @@
At times, you may want a bean to load conditionally based on various potential factors including the classpath, the configuration, the presence of other beans, etc.

The link:{api}/io/micronaut/context/annotation/Requires.html[Requires] annotation provides the ability to define one or many conditions on a bean.
The link:{api}/io/micronaut/context/annotation/Requires.html[Requires] annotation provides the ability to define one or many conditions on a bean. If a bean is used somewhere but it's requirements aren't met then `NoSuchBeanException` will be thrown. That's probably not what you want. If you want a bean to conditionally depend on a bean then mark the injection site as `@Nullable` (this is done automatically if you're using Kotlin and declare the bean with a `?`), or alternatively declare it as `Optional<Bean>`. Finally you can inject a container of interfaces, in which case unloaded beans just won't appear in the collection.

Consider the following example:

Expand Down

0 comments on commit f2cfa08

Please sign in to comment.