Organizational Research By

Surprising Reserch Topic

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 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 11, 2015 by dhananjayksharma
0 votes

Related Hot Questions

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 11, 2015 by pradip.bhoge
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 11, 2015 by sumit_jaiswalmca
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 11, 2015 by param.oncemore