spring quartz 怎么样才能让定时器在jboss启动时只执行一次

2024-12-31 08:26:34
推荐回答(1个)
回答1:

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoadParam implements ServletContextListener{
Logger logger = LoggerFactory.getLogger(LoadParam.class);
/**
* @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
*/
@Override
public void contextDestroyed(final ServletContextEvent arg0) {
}
/**
* @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
*/
@Override
public void contextInitialized(final ServletContextEvent arg0) {
arg0.getServletContext().setAttribute("contextPath", arg0.getServletContext().getContextPath());
//增加调用你要做的事情
}
}

在web.xml中增加Listener定义,其中package你自己定义


xxx.xxx.xxx.LoadParam