I am working on a project (tire page), before starting the application, I need to load data into the database, namely, price lists. How can I do this? That is, what would the price lists load and stay forever? I use Spring with xml-configurations and annotations.
- The easiest way to download through any utility working with the database using sql-files. - nick_n_a 1:59 pm
- Look towards batch ( mkyong.com/spring-batch/… ). - Chubatiy 2:49 PM
2 answers
It is possible to try liquibase - opensource project for versioning change. With its help, it is possible to make a check when the application starts for the presence of certain data. If the check fails then execute the script: sql or xml changelogs . There is integration with spring
Although it may be easier to program it yourself.
I do not use XML configuration in Spring. But I will try to help. You have a bin (class) that configures working with your database. In an XML configuration bean there is such a thing as init-method = "someCustomMethod". someCustomMethod is a method in your bean class that is called after your bean is fully initialized. And in this method you can already apply to the database and carry out manipulations with it. This will happen every time your application is deployed. Here is an example of using this approach .