2009-07-17 45 views
0

我有一個簡單的Web應用程序,打包成EAR,部署在Glassfish上。 EAR有一個Web模塊和一個EJB模塊。 Web模塊具有一個面頁面和一個ManagedBean。 Faces頁面上只有一個按鈕,並且該按鈕綁定到ManagedBean中的某個方法,然後單擊該按鈕的確會觸發該方法。從Faces BackingBean調用EJB3

管理bean:

public class Bar { 

    public Bar() { 
    } 

    @EJB StudentProfileFacade f; 

    public void hello(ActionEvent evt) { 
     System.out.println("*** f: " + f); 
    } 
} 

的EJB是沒有得到注入,我得到的錯誤是:

Exception attempting to inject Unresolved Ejb-Ref com.web.Bar/[email protected]: [email protected]@[email protected]@null into class com.web.Bar 

什麼我需要怎麼做才能讓Web模塊會發現EJB模塊和其中的EJB?

+0

EJB是否分配了全局JNDI名稱? – 2009-09-19 16:02:51

回答

0

試着做jndi查找而不是di。它可能看起來像:

private StudentProfileFacadeInt getStudentProfileFacade() { 
try { 
    InitialContext ctx = new InitialContext(); 
    return (StudentProfileFacadeInt) ctx.lookup("<application_name>/StudentProfileFacade/local"); 
} catch (Exception e) { 
    e.printStackTrace(); 
    throw new RuntimeException("couldn't lookup StudentProfileFacade", e); 
} 
} 

哪裏StudentProfileFacadeIntStudentProfileFacade本地interfejs。