Jsf PrimeFaces Push EventBusFactory.getDefault().eventBus()返回null
我对PrimeFaces 6.0 push有异议,我在这里搜索了所有问题,没有任何答案对我有帮助。我正在构建一个内部电子邮件系统,并试图根据后端事件(观察者模式)通知用户是否在数据库中插入了新电子邮件,以下是我的代码: web.xmlJsf PrimeFaces Push EventBusFactory.getDefault().eventBus()返回null,jsf,primefaces,primefaces-push,Jsf,Primefaces,Primefaces Push,我对PrimeFaces 6.0 push有异议,我在这里搜索了所有问题,没有任何答案对我有帮助。我正在构建一个内部电子邮件系统,并试图根据后端事件(观察者模式)通知用户是否在数据库中插入了新电子邮件,以下是我的代码: web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.j
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>Test Foo Email system</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- primeFaces push declaration -->
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/ *</url-pattern>
</servlet-mapping>
<!-- Ends here-->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/ *</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
通知资源类
import javax.faces.application.FacesMessage;
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;
@PushEndpoint("/notify")
public class NotifyResource {
@OnMessage(encoders = {JSONEncoder.class})
public FacesMessage onMessage(FacesMessage message) {
return message;
}
}
包括我发现这段代码需要的必需库,我已经从web下载了这些JAR,它们在我的示例中使用
atmosphere-annotations-2.4.9.jar
atmosphere-compat-jbossweb-2.0.1.jar
atmosphere-compat-tomcat-2.0.1.jar
atmosphere-compat-tomcat7-2.0.1.jar
atmosphere-runtime-2.4.9.jar
primefaces-6.0.jar
slf4j-api-1.7.22.jar
slf4j-simple-1.7.22.jar
我已经厌倦了调试我的代码,我注意到当我尝试使用它时,事件总线将为NULL(eventBus.publish()),因此我得到了java.lang.NullPointerException
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/ *</url-pattern>
</servlet-mapping>
推送Servlet
/primepush/*
/primepush/和*之间有一个空格,请尝试将其删除。Stackoverflow中有几个“重复项”。请尝试搜索它们。右边的“相关”栏已经显示了一些Hi kukeltje,谢谢你的评论,不幸的是我已经尝试了所有发布的答案,但是我无法找出我要搜索的问题的位置。一周过去了,我也是jsf的初学者。什么是服务器运行时?雄猫?尝试将cdi添加为库
atmosphere-annotations-2.4.9.jar
atmosphere-compat-jbossweb-2.0.1.jar
atmosphere-compat-tomcat-2.0.1.jar
atmosphere-compat-tomcat7-2.0.1.jar
atmosphere-runtime-2.4.9.jar
primefaces-6.0.jar
slf4j-api-1.7.22.jar
slf4j-simple-1.7.22.jar
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/ *</url-pattern>
</servlet-mapping>