How to fill database at deploytime?
I am developing a java web-site. It fetches data from http://projects.zoho.c开发者_开发问答om.
I have to fetch data using its API and want to fill database in a session.
But, I need this process occur at deploy time. Means, at first time when I deploy web, it would fill whole database and then at every session period of time it fills data automatically.
What step I should follow ?
Write a ServletContextListener which populates the database and does the work in the contextInitialized() method.
If the listener is configured in your web.xml, the servlet container will invoke your listener's contextInitialized() method when the webapp is started.
you can see hibernate3:hbm2ddl
maven plugin implementation for this purpose if your project is based on hibernate and for filling database in specific period of time you can define job in your application with quartz
This is a deployment issue, not a coding issue.
You should update your database with a script when you do your deployment.
You could automate this if you want in either ANT or Maven or whatever deployment script you are using.
Ideally the best time to do this is when your app is down, so you do not get any reads with the DB in an invalid state.
精彩评论