Can I replace a Spring bean definition at runtime?

后端 未结 11 1376
萌比男神i
萌比男神i 2020-11-30 17:44

Consider the following scenario. I have a Spring application context with a bean whose properties should be configurable, think DataSource or MailSender

11条回答
  •  清歌不尽
    2020-11-30 18:25

    Here is the nice idea of writing your own PlaceholderConfigurer that tracks the usage of properties and changes them whenever a configuration change occurs. This has two disadvantages, though:

    1. It does not work with constructor injection of property values.
    2. You can get race conditions if the reconfigured bean receives a changed configuration while it is processing some stuff.

提交回复
热议问题