import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.ymkj.credit.service.EncryptService;
public class CheckEncryptListener implements ServletContextListener{
//tomcat启动前就会执行该方法
@Override
public void contextInitialized(ServletContextEvent sce) {
ApplicationContext aContext = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext());
EncryptService sysparamService = (EncryptService) aContext.getBean("encryptService");//这是在spring.xml注入的,我是用的注解
sysparamService.checkEncrypt();
}
//tomcat启动后就会执行该方法
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
<!-- tomcat启动前校验加密是否正确 -->
<listener>
<listener-class>com.ymkj.credit.web.api.listener.CheckEncryptListener</listener-class>
</listener>