发送initiat请求(生命周期)的异常,例如监听器类(监听器事件)com.sun.faces.config.ConfigureListener

时间:2015-04-06 16:39:06

标签: eclipse spring tomcat7 jsf-2.2 mojarra

嗨请帮忙我想创建一个动态项目Spring / JSF。 我使用的技术:

  • JSF 2.2(javax.faces-2.2.10.jar)
  • Springframework 4.1.5
  • Tomcat 7.0.59
  • Eclipse Luna

我有这个错误:

GRAVE: Une exception lors de l'envoi de requête a initié un évènement cycle de vie (lifecycle event) pour l'instance de classe à l'écoute (listener event) com.sun.faces.config.ConfigureListener
java.lang.UnsupportedOperationException
    at javax.faces.context.FacesContext.getExceptionHandler(FacesContext.java:287)
    at javax.faces.event.ExceptionQueuedEventContext.getListenersForEventClass(ExceptionQueuedEventContext.java:262)
    at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2107)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:287)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:245)
    at com.sun.faces.application.WebappLifecycleListener.requestDestroyed(WebappLifecycleListener.java:125)
    at com.sun.faces.config.ConfigureListener.requestDestroyed(ConfigureListener.java:375)
    at org.apache.catalina.core.StandardContext.fireRequestDestroyEvent(StandardContext.java:6223)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:215)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

有代码: 的web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>DemandeAch</display-name>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
    <context-param>
        <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
        <param-value>0</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
        <param-value>true</param-value>
    </context-param>
</web-app>

SpringConfiguration.java/MyWebAppInitializer.java

@Configuration
@ComponentScan
public class SpringConfiguration {

}

public class MyWebAppInitializer implements WebApplicationInitializer {

@Override
public void onStartup(ServletContext container) throws ServletException {
    // create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(SpringConfiguration.class);

    // Manage lifecycle of the root application context
    container.addListener(new ContextLoaderListener(rootContext));

}
}

HelloSpringService.java

@Service
public class HelloSpringService {
public String sayHello(){
        return "Hello from Spring Service";
    }
}

控制器

@ManagedBean
public class HelloController {

    @ManagedProperty("#{helloSpringService}")
    private HelloSpringService helloSpringService;
    public String showHello(){
        return helloSpringService.sayHello();
    }
}

的index.xhtml

<h:head></h:head>
<h:body>
    managed bean says :
    #{helloController.showHello()}
</h:body>

请帮忙:/ 非常感谢。

1 个答案:

答案 0 :(得分:1)

错误是:

GRAVE: Erreur lors de la configuration de la classe d'écoute de l'application (application listener) com.sun.faces.config.ConfigureListner
java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListner

在您的web.xml中,可能会出现以下情况:

<listener>
     <listener-class>com.sun.faces.config.ConfigureListner</listener-class>
</listener>

正如您所看到的,侦听器类名称是错误的。不是ConfigureListner,而是ConfigureListener。因此,请尝试将web.xml更改为:

<listener>
     <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

修改

修复了侦听器的名称后,显示了另一个错误:

GRAVE: Une exception lors de l'envoi de requête a initié un évènement cycle de vie (lifecycle event) pour l'instance de classe à l'écoute (listener event) com.sun.faces.config.ConfigureListener
java.lang.UnsupportedOperationException
    at javax.faces.context.FacesContext.getExceptionHandler(FacesContext.java:287)

正如评论中所述,&#34; ConfigureListener通常是自动注册的,尝试从web.xml中删除监听器,也是过时的,使用javax.faces.webapp.FacesServlet。&#34; 。相反,你可以使用这样的东西:

<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.jsf</url-pattern> <!-- or one of your own --> 
</servlet-mapping>