实现 以下接口:
ServletContextListener,ServletContextAttributeListener,
HttpSessionListener,HttpSessionAttributeListener,
HttpSessionActivationListener,HttpSessionBindingListener,
ServletRequestListener,ServletRequestAttributeListener
实现以下方法:
public void contextInitialized(ServletContextEvent evt) {
logger.info("修复 数据库");
ctx=WebApplicationContextUtils.getWebApplicationContext(evt.getServletContext());
RepairServiceI rep= (RepairServiceI) ctx.getBean("repariService");
rep.repair();
}
在web.xml里面完成以下配置,注意写在spring 监听的下面
<listenter>
<listenter-class>sy.listener.RepairListener</listener>
</listenter>
网友评论