目前我正在尝试删除 ConversationScoped Stateful Session Bean (SFSB)。ConversationScope 由 CDI 容器管理,SFSB 的生命周期由 EJB 容器管理。这个对吗?
在我的控制器中,我试图通过调用 SFSB 的方法并调用 @Remove 带注释的方法来销毁 SFSB 来结束对话。
对话可以毫无问题地结束,但我无法破坏 SFSB。
Weld Reference Guide 中的代码示例(WELD Conversation Scope):
@ConversationScoped @Stateful
public class OrderBuilder {
private Order order;
private @Inject Conversation conversation;
private @PersistenceContext(type = EXTENDED) EntityManager em;
@Produces public Order getOrder() {
return order;
}
public Order createOrder() {
order = new Order();
conversation.begin();
return order;
}
public void addLineItem(Product product, int quantity) {
order.add(new LineItem(product, quantity));
}
public void saveOrder(Order order) {
em.persist(order);
conversation.end();
}
@Remove
public void destroy() {}
}
控制器:
@Named
@SessionScoped
public class TestController implements Serializable{
@Inject
private OrderBuilder orderBuilder;
...
public String checkout(Order order){
orderBuilder.saveOrder(order);
orderBuilder.destroy();
return "success";
}
}
在我调用了 testController.checkout(order) 之后,我得到了这个异常:
javax.servlet.ServletException: java.lang.reflect.InvocationTargetException javax.faces.webapp.FacesServlet.service(FacesServlet.java:321) org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) 根本原因
javax.faces.el.EvaluationException:
java.lang.reflect.InvocationTargetException javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98) com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98) javax.faces.component.UICommand.broadcast (UICommand.java:311) javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) com.sun.faces.lifecycle.InvokeApplicationPhase.execute (InvokeApplicationPhase.java:77) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) javax.faces.webapp.FacesServlet .service(FacesServlet.java:308) org.jboss.weld.servlet.ConversationPropagationFilter。doFilter(ConversationPropagationFilter.java:67)
有任何想法吗?
谢谢