EJB在企业应用程序中无法识别

时间:2010-02-13 09:02:52

标签: jsf jpa glassfish ejb

我正在使用Eclipse,我想使用Glassfish和MySQL创建一个企业应用程序。

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

在WeatherEJB项目中,我使用JPA从表生成实体,并且还创建了一个名为CountryDAO的无状态远程会话bean,它实现了CountryDAOBean,以便包裹生成的实体Country。

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

然后,在WeatherWeb项目中,我创建了一个名为CountryController的托管bean(在'request'范围内),如下所示:

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/countryDao@jndi: service.CountryDAO@null@service.CountryDAO@Session@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/countryDao@jndi: service.CountryDAO@null@service.CountryDAO@Session@null into class managedBeans.CountryController

root cause

javax.faces.FacesException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref managedBeans.CountryController/countryDao@jndi: service.CountryDAO@null@service.CountryDAO@Session@null into class managedBeans.CountryController

root cause

com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref managedBeans.CountryController/countryDao@jndi: service.CountryDAO@null@service.CountryDAO@Session@null into class managedBeans.CountryController

root cause

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

我错过了什么?或者我做错了什么?

1 个答案:

答案 0 :(得分:1)

实际上,而不是实现类:

@EJB
CountryDAO countryDao;

我应该使用界面:

@EJB
CountryDAOBean countryDao;