At around 22:15 he says an app context goes through around 15 steps to initialize itself. Where can I see a summary of the steps/a diagram? I cannot find one on the reference docs.
Normally we use @Primary to tell Spring which bean to use when there are several available, but as you know, a Spring application will not start if a bean is missing. This is where @Fallback can be useful, meaning that if no bean is provided then use the @Fallback one, and if one is provided there is no need to mark it as @Primary as I understand it.
Spring Boot will step back from autoconfiguring beans if it finds an autowire candidate in the context (@ConditionalOnMissingBean). @Fallback ensures your standard still works, while you can have additional beans that you only need for a special case.
I imagine this could be useful in more complex configuration scenarios. Say you have a configuration C that you share between multiple modules. It provides (among other things) a bean Z implementing some interface. In module A you want to use the module's own bean X in favor of Z. So you need to leave Z un-annotated and annotate X with @Primary. In module B you want to use Z in favor of the module's own bean Y, but Z is not annotated with @Primary. Now you can annotate the "local" bean Y with @Fallback, so if the shared configuration C is present, it will prefer bean Z.
At around 22:15 he says an app context goes through around 15 steps to initialize itself. Where can I see a summary of the steps/a diagram? I cannot find one on the reference docs.
I can't really think of a use case for @Fallback, it seems like @Primary can do everything.. thoughts??
Normally we use @Primary to tell Spring which bean to use when there are several available, but as you know, a Spring application will not start if a bean is missing. This is where @Fallback can be useful, meaning that if no bean is provided then use the @Fallback one, and if one is provided there is no need to mark it as @Primary as I understand it.
@@diegomx80 I understand how it works, but u can achieve the same thing using @Primary, no?
@@diegomx80 if u define a primary (1) and a none primary bean (2) then (2) is the fallback of (1), no?
Spring Boot will step back from autoconfiguring beans if it finds an autowire candidate in the context (@ConditionalOnMissingBean). @Fallback ensures your standard still works, while you can have additional beans that you only need for a special case.
I imagine this could be useful in more complex configuration scenarios.
Say you have a configuration C that you share between multiple modules. It provides (among other things) a bean Z implementing some interface.
In module A you want to use the module's own bean X in favor of Z. So you need to leave Z un-annotated and annotate X with @Primary.
In module B you want to use Z in favor of the module's own bean Y, but Z is not annotated with @Primary. Now you can annotate the "local" bean Y with @Fallback, so if the shared configuration C is present, it will prefer bean Z.