使用ServletContextListener并在中定义它web.xml: (您将创建一个实现ServletContextListener并实现该contextInitialized()方法的类,并在其中放置初始化代码)