我的聽衆是填充緩存(陶土),如果出現錯誤,在應用程序啓動,的ExceptionInInitializerError異常。我想獲取服務器名稱(如HttpServletRequest - getServerName())以知道發生了什麼。獲取服務器名稱的ContextLoaderListener
我該如何獲得這些信息?
import javax.servlet.ServletContextEvent;
import net.f.core.service.util.CacheUtil;
import org.apache.log4j.Logger;
import org.springframework.web.context.ContextLoaderListener;
/**
* Application Lifecycle Listener implementation class OnContextLoadListener
*
*/
public class OnContextLoadListener extends ContextLoaderListener {
private static final Logger log = Logger
.getLogger(OnContextLoadListener.class);
@Override
public void contextDestroyed(
@SuppressWarnings("unused") ServletContextEvent sce) {
// nothing here
}
@Override
public void contextInitialized(
@SuppressWarnings("unused") ServletContextEvent sce) {
try {
CacheUtil.getInstance();
} catch (ExceptionInInitializerError e) {
log.error("Problem with application start!", e);
// notify me
}
}
我很好奇,爲什麼你要擴展Spring的'ContextLoaderListener',然後超越其方法。你留下的只是一個沒有Spring行爲的簡單的'ServletContextListener'。 – skaffman 2009-11-20 10:22:11