2010-02-13 71 views
0

我正在使用Eclipse,我想使用Glassfish和MySQL创建企业应用程序。EJB在企业应用程序中未被识别

我创建了一个名为WeatherEJB和WeatherWeb的EJB和WEB模块的企业应用程序项目。

在WeatherEJB项目中,我使用JPA生成实体表,使用JPA创建一个无状态的远程会话bean,名为CountryDAO,实现CountryDAOBean,以便覆盖生成的实体Country。

在WeatherWeb项目中,我添加了对Java Build浴中的WeatherEJB项目的引用,项目引用和模块依赖项。

然后,在WeatherWeb项目中,我创建了一个名为CountryController(在“请求”范围)托管bean,它看起来像这样:

import javax.ejb.EJB; 

import model.Country; 

import service.CountryDAO; 

public class CountryController 
{ 
    @EJB 
    CountryDAO countryDao; 

    private Country country; 

    public CountryController() 
    { 
     country = new Country(); 
    } 

    public String saveCountry() 
    { 
     String returnValue = "success"; 

     try 
     { 
      countryDao.saveCountry(country); 
     } 
     catch (Exception e){ 
      e.printStackTrace(); 
      returnValue = "failure"; 
     } 
     return returnValue; 
    } 

    public Country getCountry(){ 
     return country; 
    } 

    public void setCountry(Country country){ 
     this.country = country; 
    } 
} 

虽然我可以成功部署在Glassfish应用程序,当我尝试访问使用CountryController的jsf,我得到以下错误:

type Exception report 

message 

descriptionThe server encountered an internal error() that prevented it from fulfilling this request. 

exception 

javax.servlet.ServletException: javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref managedBeans.CountryController/[email protected]: [email protected]@[email protected]@null into class managedBeans.CountryController 

root cause 

javax.faces.FacesException: javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref managedBeans.CountryController/[email protected]: [email protected]@[email protected]@null into class managedBeans.CountryController 

root cause 

javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref managedBeans.CountryController/[email protected]: [email protected]@[email protected]@null into class managedBeans.CountryController 

root cause 

com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref managedBeans.CountryController/[email protected]: [email protected]@[email protected]@null into class managedBeans.CountryController 

root cause 

javax.naming.NameNotFoundException: service.CountryDAO#service.CountryDAO not found 

我在想什么?或者我做错了什么?

回答

1

事实上,而不是实现类:

@EJB 
CountryDAO countryDao; 

我应该使用的接口:

@EJB 
CountryDAOBean countryDao;