Execute code after Glassfish Web Deployment [duplicate]

随声附和 提交于 2019-12-01 11:41:43

问题


I'm trying to run a java web service on Glassfish. There is some initialization code that sets a few variables and retrieves some information from the Glassfish environment itself. I have that code in a static initializer inside the @WebService class, however this code appears to be called too early, it gets run as soon as the WebService endpoint is deployed, whereas I need it to run once the whole web service is successfully deployed.

I tried moving the code into the constructor of the WebService class, however then that code was only run when I went into the Tester web page and sent some data to make the web methods run.

Is there any way to set up some initialization code to be run as soon as the whole web service deployment is completed?


回答1:


Option 1: In Glassfish you have the Lifecycle modules

Option 2: You also have the ability to code a ServletContextListener to be triggered when the context is loaded:

public class MyServlet implements ServletContextListener {

  public void contextInitialized(ServletContextEvent e) {
         // implementation code
  }

  public void contextDestroyed(ServletContextEvent e) {
         // implementation code
  }
}

Reference:

  • About Life Cycle Modules
  • Example of ServletContextListener



回答2:


Yes @Jaynathan Leung, with soapUI can you deployment the web services and testing your programming with input and output data. I hope help you. :)



来源:https://stackoverflow.com/questions/10603521/execute-code-after-glassfish-web-deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!