[英]Why is a CDI Managed Bean in faces-config.xml not registered as an obersver?
我實現了一個CDI Bean,它正在觀察另一個Bean的事件:
@SessionScoped
public class FixedItemController implements Serializable {
....
public void onWorkflowEvent(@Observes WorkflowEvent workflowEvent) throws AccessDeniedException {
logger.info("evaluate event...");
....
}
....
}
只要我在JSF頁面中使用其默認名稱為“ fixedItemController”的Bean,此方法就可以正常工作。
但是,如果我像這樣在faces-config.xml中聲明該bean的另一個實例:
<managed-bean>
<managed-bean-name>myOrderItemController</managed-bean-name>
<managed-bean-class>org.imixs.marty.workflow.FixedItemController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>childItemProperty</property-name>
<property-class>java.lang.String</property-class>
<value>_orderItems</value>
</managed-property>
</managed-bean>
第二個實例(myOrderItemController)不會自動注冊為我的WorkflowEvent的觀察者。
我該怎么做,以確保我的第二個實例(由faces-config.xml聲明)將立即實例化並注冊為我的workitemEvent的觀察者?
faces-config.xml
不注冊CDI托管bean。 它注冊JSF管理的bean。 實際上,您的#{myOrderItemController}
是JSF托管的bean。 就像您使用@ManagedBean
而不是@Named
。 JSF bean管理工具不會掃描特定於CDI的@Observes
注釋。
保留它為CDI管理的bean。 無論您嘗試解決什么問題,都認為必須將其注冊在faces-config.xml
正確的解決方案,而必須使用CDI API而不是JSF API來解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.