在Spring中动态创建bean [英] Dynamic creation of beans in Spring
问题描述
我需要这样做使我的应用程序完全可配置...如果我将来添加一个新的字段,我将需要在db中添加一个字段,而bean setter和getter将是
谢谢
动态注册bean。您可以使用 BeanDefinitionBuilder 为此目的请参阅此处的示例。但是,如@Darren所说,通过数据库查找来撬动一个bean不是一个明智的主意。
Is there a way in spring wherein we can read the fields of a bean from the DB table and create a complete bean class - with getters and setters on server startup????
I require this to make my application completely configurable...as in if I have to add a new field in future , all I would require would be adding a field in the db and the bean setters and getters would be available to me.
Thanks
You could try approaches for dynamically registering beans . You could use the BeanDefinitionBuilder for this purpose . See a sample here . But as @Darren says , It's not a wise idea to creak a bean via DB lookup .
这篇关于在Spring中动态创建bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!