Spring Framework 6.2: Core Container Revisited by Juergen Hoeller @ Spring I/O 2024

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 7

  • @MORETHANOVERGROWN
    @MORETHANOVERGROWN 5 месяцев назад +1

    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.

  • @ilkou
    @ilkou 5 месяцев назад

    I can't really think of a use case for @Fallback, it seems like @Primary can do everything.. thoughts??

    • @diegomx80
      @diegomx80 5 месяцев назад +2

      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.

    • @ilkou
      @ilkou 5 месяцев назад

      @@diegomx80 I understand how it works, but u can achieve the same thing using @Primary, no?

    • @ilkou
      @ilkou 5 месяцев назад

      @@diegomx80 if u define a primary (1) and a none primary bean (2) then (2) is the fallback of (1), no?

    • @hariseldon02
      @hariseldon02 5 месяцев назад

      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.

    • @silberwolfSR71
      @silberwolfSR71 5 месяцев назад +1

      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.