we develops a project name as FirstApplication for sending,consuming messages from Activemq and deployed in Tomcat7.After deploying,we have to trigger http://localhost:8080/FirstApplication/PackageName/SecondConsumer link only 1 time.So far it's fine.
My doubt,later If we restart the server,again first time we have to trigger that servlet corresponding link.Instead of doing like this,I want to configure.
Note: what I want,servlet should be evaluate automatically whenever Tomcat server start.servlet placed under WebApps/FirstApplication/WEB-INF/src/classes/PackageName/SecondConsumer.java.
For this, I tried with the following code using servletContextListenerclass.
public class SecondConsumer extends HttpServlet implements ServletContextListener{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//my business code
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
}
}
and added <Listener>in my web.xml(which is placed under WebApps/FirstApplication/WEB-INF/web.xml) file in the following way.
<listener>
<listener-class>PackageName.SecondConsumer</listener-class>
</listener>
If you observe my code, I didn't implement any code under contextInitialized and contextDestroyed methods.Just i want to evaluate this servlet code while server starting time.
I tried in the above way,it's not working.
please can anyone suggest me.
Thanks.