Can a Stored Procedure be called during initialization of ActionServlet [init() method] using ibatis?
Yes, assuming ibatis is initialized before ActionServlet.init
is executed, which it will be if you initialise it in a ServletContextListener.
However, I would consider whether you should be doing your application initialisation in a subclass of ActionServlet.init
. I would do it in an implementation of ServletContextListener's contextInitialized
method instead.
There's a post from 2002 by Craig McClanahan that explains why this is better practice:
"The reason for this is that the servlet spec does not guarantee that a servlet will be loaded once and then left in memory the entire lifetime of the app, although in principle most containers do that for heavily requested servlets. For example, it is entirely legal for a container to throw out the Struts controller servlet, and then re-initialize it again, as many times as it wants to, within the lifetime of a webapp.
The nice thing about ServletContextListener is that you're guaranteed that contextInitialized() and contextDestroyed() are only called at the times you need them (webapp startup and webapp shutdown), no matter what happens with servlets and JSP pages in the middle. But this only works on a 2.3 or later system, where this API was added."