EJB在企业应用程序中不被识别
我正在使用 Eclipse,我想使用 Glassfish 和 MySQL 创建一个企业应用程序。
我创建了一个企业应用程序项目,包含 EJB 和 WEB 模块,名为 WeatherEJB 和 WeatherWeb。
在 WeatherEJB 项目中,我使用 JPA 从表生成实体,并且还创建了一个名为 CountryDAO 的无状态远程会话 bean,它实现了 CountryDAOBean,以便包装生成的实体 Country。
在 WeatherWeb 项目中,我在 Java 构建池中添加了对 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@[email protected]@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@[email protected]@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@[email protected]@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@[email protected]@Session@null into class managedBeans.CountryController
root cause
javax.naming.NameNotFoundException: service.CountryDAO#service.CountryDAO not found
我缺少什么?或者我做错了什么?
I am working on Eclipse and I want to create an enterprise application using Glassfish and MySQL.
I created a Enterprise Application Project, with EJB and WEB modules, named WeatherEJB and WeatherWeb.
In the WeatherEJB project I generated entities from tables, using JPA and also I created a stateless remote session bean, called CountryDAO, which implements CountryDAOBean, in order to wrap over the generated entity Country.
In the WeatherWeb project I added references to the WeatherEJB project in the Java Build bath, project references and module dependencies.
Then, in the WeatherWeb project, I created a managed bean called CountryController (at 'request' scope), which looks like this:
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;
}
}
Although I can deploy successfully the application on Glassfish, when I try to access a jsf that uses the CountryController, I get the following errors:
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@[email protected]@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@[email protected]@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@[email protected]@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@[email protected]@Session@null into class managedBeans.CountryController
root cause
javax.naming.NameNotFoundException: service.CountryDAO#service.CountryDAO not found
What am I missing? or what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是实现类:
实际上,我应该使用接口
Actually, instead of the implementation class:
I should have used the interface: