I want to fill some tables of my DB from a text file on startup, I want my initialization method to be called only when my application do start.
I am using Spring (+MVC) and Hibernate with MySQL.
how can I do?
You can create an application listener, it's designed specifically for such needs. In this case it will be executed every time context is started (or refreshed).
@Component
public class DatabaseFillerOnStartup implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With