简体   繁体   English

如何使用@WebListener部署Java EE侦听器

[英]how to deploy java EE listener using @WebListener

I want to implement a new listener (using the servlet 3.0 spec). 我想实现一个新的侦听器(使用Servlet 3.0规范)。

@WebListener
public class LoadingManager implements ServletContextListener 
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {

    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {


    }

}

I package the listener in a jar and I want to know which is the better deployment mode 我将侦听器包装在一个jar中,我想知道哪种部署方式更好

  • Put the jar on the tomcat/lib 将罐子放在tomcat / lib上
  • Put the jar inside webapps/My-Application/lib 将罐子放入webapps / My-Application / lib

If I deploy the jar under the tomcat/lib, how much time the method contextInitialized will be performed (knowing that I have a set of webapplicatio deployed on my tomcat instance) 如果将jar部署在tomcat / lib下,则将执行contextInitialized方法多少时间(知道我在tomcat实例上部署了一组webapplicatio)

Thanks in advance 提前致谢

Better to add it in the webapps/My-Application/lib so that it can be used based on individual application and not for all the applications 最好将其添加到webapps / My-Application / lib中,以便可以基于单个应用程序而不是所有应用程序使用它

Even Gimby has some good points in the comment. 甚至Gimby在评论中也有一些优点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM