【发布时间】:2010-02-13 09:02:51
【问题描述】:
我正在开发 Eclipse,我想使用 Glassfish 和 MySQL 创建一个企业应用程序。
我创建了一个企业应用程序项目,包含 EJB 和 WEB 模块,名为 WeatherEJB 和 WeatherWeb。
在 WeatherEJB 项目中,我使用 JPA 从表中生成实体,还创建了一个名为 CountryDAO 的无状态远程会话 bean,它实现了 CountryDAOBean,以包装生成的实体 Country。
在 WeatherWeb 项目中,我添加了对 Java Build bath 中 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/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
我错过了什么?还是我做错了什么?
【问题讨论】: