dynamic creation of beans in spring

dynamic creation of beans in spring  using -'spring,dynamic,javabeans,creation'

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.


asked Oct 7, 2015 by shegokar.anjeet
0 votes

3 Answers

0 votes

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 .

answered Oct 7, 2015 by vickeykumar66
0 votes

1: Improve your accept-rate

2: You might benefit from something like an ORM approach (Hibernate or JPA). Another slightly different approach that might suite you is the Active Record pattern as implemented in, forinstance, ActiveJDBC.

Spring does not, in itself, offer anything like what you are after, but using spring-jpa together with Hibernate might get you a bit closer towards your goal. If, OTOH, you want auto-generated code you could also look at something like Spring-Roo

answered Oct 7, 2015 by 20shahi
0 votes

You might want to think about this a little more. Even if you made your fields totally configurable, you will still have to write the code that accesses them. And given that you are going to have to write code anyway, might as well keep everything in code. It's much simpler that way.

answered Oct 7, 2015 by kinnari