views:

194

answers:

1

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?

+1  A: 

Actually, instead of the implementation class:

@EJB
CountryDAO countryDao;

I should have used the interface:

@EJB
CountryDAOBean countryDao;
melculetz