com.sun.faces.config.InitFacesContext.cleanupInitMaps中的Nullpointer异常

时间:2013-05-12 00:34:42

标签: jsf tomcat

我无法将war文件部署到tomcat服务器。我最终会遇到以下异常。

 SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/BatchApp-1.0.0.M1]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at com.sun.faces.config.InitFacesContext.cleanupInitMaps(InitFacesContext.java:281)
    at com.sun.faces.config.InitFacesContext.<init>(InitFacesContext.java:107)
    at com.sun.faces.config.FacesInitializer.onStartup(FacesInitializer.java:115)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5280)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 11 more

May 11, 2013 5:28:05 PM org.apache.catalina.startup.HostConfig deployWAR
SEVERE: Error deploying web application archive C:\AppDev\Tomcat7.0\webapps\BatchApp-1.0.0.M1.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/BatchApp-1.0.0.M1]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

我进一步调试了它,看起来像com.sun.faces.config.InitFacesContext中的代码@getInitContextServletContextMap()方法我最终会返回空指针。

 static Map getInitContextServletContextMap() {
    ConcurrentHashMap initContextServletContext = null;
    try {
        Field initContextMap = FacesContext.class.getDeclaredField("initContextServletContext");
        initContextMap.setAccessible(true);
        initContextServletContext = (ConcurrentHashMap)initContextMap.get(null);
    } catch (Exception e) {
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.log(Level.FINEST, "Unable to get (init context, servlet context) map", e);
        }
    }
    return initContextServletContext;
}

清除服务器正在寻找“initContextServletContext”,但在哪里设置它?

请告诉我如何解决此问题。

1 个答案:

答案 0 :(得分:8)

有完全相同的错误。这是一个依赖性问题:我使用的是Oracle的JSF(2.2.1)实现,但我的一个Maven依赖项是拉入Apache MyFaces。

发生的事情是您显示的代码片段(来自Oracle实例)尝试访问FacesContext的静态私有字段。但是类加载器已经加载了FacesContext的MyFaces实现,它没有该字段。因此barf。

检查您的依赖项。我打赌你会发现你有两个不同版本或两个不同的JSF实现。