I want to execute some operation of database at a time of application deployment.
For Front I am using JSP, For Back-end Spring-mvc and for database operation Hibernate.
How can I achieve this?
I want to execute some operation of database at a time of application deployment.
For Front I am using JSP, For Back-end Spring-mvc and for database operation Hibernate.
How can I achieve this?
You need to add the servlet entry in the web.xml with load-on-startup as 1 which will load during deployment , so you can perform the database operations.. Example
<servlet>
<display-name>MyClass</display-name>
<servlet-name>MyClass</servlet-name>
<servlet-class>com.controller.MyClass</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyClass</servlet-name>
<url-pattern>/MyClass</url-pattern>
</servlet-mapping>
Enjoy bro :)
Create a class write your code which you want to execute at time of application deployment and register it with Spring.
Spring will execute it at time of application deployment, as all beans are Singleton(default)
and are scanned at time of creating Application Context. Moreover you can also implement InitializingBean, if you want to complete some prerequisite before executing the bean code.