Spring Tips: Programmatic Bean Registration in Spring Framework 5.0

Sdílet
Vložit
  • čas přidán 5. 07. 2024
  • Speaker: Josh Long
    / starbuxman
    Hi Spring fans! in this installment, we'll look at different ways to register beans with Spring, culminating in the new programmatic bean registration functionality in Spring 5.
  • Věda a technologie

Komentáře • 5

  • @Hakucho64
    @Hakucho64 Před 7 lety +2

    Hey Josh, nice presentation as usual. I was hoping there was going to be new support for switching bean implementations at runtime, after the application has been running for a while, e.g. in response to some change in the environment. What's the best way to do that please?

    • @aakoss
      @aakoss Před 7 lety

      Would feature toggles be useful in such situations?

    • @Hakucho64
      @Hakucho64 Před 7 lety +2

      Yes, my question to Josh was more about how to get the Spring application context to start providing one implementation of some interface instead of another, e.g. at startup you might register a NoOpPersonServiceImpl under the PersonService interface, then in response to some environmental change, switch that bean to be backed by some other implementation, e.g. a DatabaseBackedPersonServiceImpl.

  • @vinu_varghese
    @vinu_varghese Před 7 lety +3

    Nice feature, is it possible to use the registerBean while the app is running via the reference to the applicationContext

    • @aakoss
      @aakoss Před 7 lety +2

      Yes this is possible with a handle to the bean factory. However the context would need to be refreshed for any effect at runtime. This needs to be carefully and infrequently if not rare.