我有一個類,看起來像這樣:如何在用戶類實例化後調用CDI?
@Named
public class TableView {
@PersistenceContext protected EntityManager em;
@Resource protected UserTransaction utx;
當然,我可以在我的豆建設這樣的過程中獲得一個實例:
@Inject private TableView view;
我相信這是CDI具有填寫EntityManager和UserTransaction。但是,在我的用戶類實例化後,我有時需要另一個TableView實例,那麼我如何獲得它?顯然
TableView anotherView = new TableView();
將無法工作,因爲EM和UTX將是無效的。那麼如何在進行注射後獲得新的工作實例?
此鏈接可能會解決您的問題.. http://stackoverflow.com/questions/25153624/how-to-instantiate-more-cdi-beans-for-one-class – Ankit
@Ankit這是有趣的,但沒有相當幹。我正在尋找一個運行時API來實例化bean。 – AlanObject
接口['Instance'](https://docs.jboss.org/cdi/api/1.1/javax/enterprise/inject/Instance.html)和方法'get()'。 '實例 tableViewInstance; TableView newInstance = tableViewInstance.get();' –
Geinmachi