How to create spring bean config file that sets it

2019-06-09 05:26发布

I have an excel file that contain columns of data, my target is to create objects out of this data, where these objects have relationships with each other, and send their fully initialized parent object to an enterprise application for validation and insertion into the database.

Let's say I manage to insert all this excel data into a staging(first round) database. Is there any way that I could create a bean config file that can create object hierarchies, where each object has properties retrieved from a database column?

For a start:

Column 1=> 1 2 3 5 6 7
Column 2=> a v d e f g
Column 3=> Some primary key column.

<bean name="myDomainObject" class="abcd.pqr.DomainObject1">
     <property name="column1" value="???" />
     <property name="column2" value="???" />
</bean>

I would like a config file to be created that has, say 6 domain objects, and the values come from the database.

Next step could be trying to create a complex object hierarchy, where myDomainObject could be nested inside some myParentDomainObject.

My intention is to create domain objects out of a database, so that my test cases can easily hit the application, with fully configured test objects. It could also be used to load data through an API.

标签: spring config
1条回答
何必那么认真
2楼-- · 2019-06-09 05:35

Spring is the wrong tool for the job here, I think. If you have the objects in a database, why not use JPA/Hibernate and a meaningful data model to do this for you?

You would create your beans (in whatever object graph they form), then annotate them with some JPA annotations, and let your JPA implementation do the work of pulling them from the DB into your object graph.

查看更多
登录 后发表回答