Search code examples
springdynamicjavabeanscreation

Dynamic creation of beans in Spring


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


Solution

  • 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 .