我有一个使用@ConversationScoped 的CDI bean。当我尝试为 Conversation 对象执行 @Inject 时,我得到了 NPE。
@ConversationScoped
@Named("customerbean")
public class CustomerBean implements Serializable {
@Inject
private Conversation conversation;
private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("ba");
private EntityManager em;
private Customer customer;
boolean disabled;
public CustomerBean() {
beginConversation();
customer = new Customer();
em = emf.createEntityManager();
disabled = false;
}
private void beginConversation() {
if (this.conversation.isTransient()) {
this.conversation.begin();
return;
}
throw new IllegalStateException();
}
我在 WEB-INF 目录中有 beans.xml 文件(虽然是空的)。异常如下所示:
INFO: Exception when handling error trying to reset the response.
com.google.common.collect.ComputationException: java.lang.RuntimeException: java
.lang.NullPointerException
at com.google.common.collect.ComputingConcurrentHashMap$ComputingMapAdap
ter.get(ComputingConcurrentHashMap.java:397)
at org.jboss.weld.bean.proxy.ClientProxyProvider.getClientProxy(ClientPr
oxyProvider.java:102)
at org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolve
r.java:115)
at org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResol
ver.java:96)
at org.jboss.weld.environment.servlet.util.ForwardingELResolver.getValue
(ForwardingELResolver.java:49)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELR
esolver.java:176)