开发者

Loading a class method when Apache Axis 2 starts up

I need to execute a static method in a Java cla开发者_Go百科ss when the Apache Axis 2 starts, or something which could be done in an application scope.

Please suggest.


You could implement a javax.servlet.ServletContextListener and add it to your deployment descriptor (web.xml):

<listener>
    <listener-class>your.pack.age.path.YourServletContextListener</listener-class>
</listener>

The contextInitialized method will be called immediately after your servlet context is loaded so you can place your static method call inside.

One other way you could do it is to extend Axis2’s Servlet and do your initialization there.

In web.xml you replace the Axis2 Servlet with your own:

<servlet>
  <servlet-name>Axis2Servlet</servlet-name>
  <servlet-class>your.pack.age.path.YourAxis2Servlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

Your Servlet:

package your.pack.age.path;
import org.apache.axis2.transport.http.AxisServlet;

public class YourAxis2Servlet extends AxisServlet {

  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    // your initialization code here
    //...
  }  
  //...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜