dynamically change spring beans

前端 未结 5 1963
我在风中等你
我在风中等你 2021-01-01 01:24

how do I dynamically change the properties of a bean at runtime using java spring? I have a bean mainView, which should use as property \"class\" either \"class1\" or \"clas

5条回答
  •  醉话见心
    2021-01-01 01:44

    I believe you can write a class that implements BeanFactoryPostProcessor. If a bean of this class exists in the XML configuration file (alongside your other beans), Spring will automatically call its postProcessBeanFactory(ConfigurableListableBeanFactory) method. The ConfigurableListableBeanFactory object handed to this method can be used to change any bean definitions before Spring goes to work initializing them.

提交回复
热议问题