我實現了一個CDI豆從另一豆觀察事件:爲什麼在faces-config.xml中的CDI託管Bean沒有註冊爲obersver?
@SessionScoped
public class FixedItemController implements Serializable {
....
public void onWorkflowEvent(@Observes WorkflowEvent workflowEvent) throws AccessDeniedException {
logger.info("evaluate event...");
....
}
....
}
這工作得很好,只要我使用JSF頁面豆,其默認名稱「fixedItemController」。
但如果我聲明bean的另一個實例在faces-config.xml中像這樣:
<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的觀察者?
感謝 - 所以你的意思是,我必須使用beans.xml描述符而不是faces-config.xml? – Ralph
取決於具體的功能要求。通常,您只使用註釋/限定符/生產者,並將beans.xml保留爲原來的內容。 – BalusC