I\'m in the \"how-to\" phase with Apache CXF
and would like to know if there\'s a way to call a method when the server is started.
It would be similar to a
So, If you are using CXF Servlet
to serve Web Service
request, then you can create ServletContextListener
and contextInitialized
method will be called on deployment or on server start up if the application is already deployed.
To do that create class which will implement ServletContextListener
:
public class YourContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
//This method is called by the container on start up
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
Then define that listener in your web.xml
:
<listener>
<listener-class>your.package.YourContextListener</listener-class>
</listener>
In the contextInitialized
method you can get servlet context by using:
ServletContext context = sce.getServletContext();
And you can set as many attributes as you want to be available into whole application scope.