-4

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?

Anthon
  • 69,918
  • 32
  • 186
  • 246
Chirag Panara
  • 15
  • 1
  • 1
  • 8

3 Answers3

0

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 :)

0

You need to create a class which will implement ServletContextListener. Please refer this and this link. Hope it will help. :)

Community
  • 1
  • 1
Badal
  • 376
  • 4
  • 11
0

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.

Arpit Aggarwal
  • 27,626
  • 16
  • 90
  • 108