侦听器实例 class(侦听器事件)com.sun.faces.config.ConfigureListener 的初始请求(生命周期)发送异常
Exception in sent of the initiat request (lifecycle) for instance of listener class (listener event) com.sun.faces.config.ConfigureListener
您好,请帮助我创建一个动态项目 Spring/JSF。
我用的技术:
- JSF 2.2 (javax.faces-2.2.10.jar)
- Spring 框架 4.1.5
- Tomcat 7.0.59
- 日蚀月神
我有这个错误:
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>
请帮忙:/
非常感谢。
错误是:
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>
如您所见,监听器 class 名称是错误的。不是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)
正如评论中所说,"The ConfigureListener is normally automatically registered, try remove listener from web.xml, also is obsolete, use javax.faces.webapp.FacesServlet."。相反,你可以使用这样的东西:
<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>
您好,请帮助我创建一个动态项目 Spring/JSF。 我用的技术:
- JSF 2.2 (javax.faces-2.2.10.jar)
- Spring 框架 4.1.5
- Tomcat 7.0.59
- 日蚀月神
我有这个错误:
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>
请帮忙:/ 非常感谢。
错误是:
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>
如您所见,监听器 class 名称是错误的。不是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)
正如评论中所说,"The ConfigureListener is normally automatically registered, try remove listener from web.xml, also is obsolete, use javax.faces.webapp.FacesServlet."。相反,你可以使用这样的东西:
<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>