Search code examples
jsfjbossejbjsf-1.2

Inject an EJB into a JSF managed bean


I have a war application with some JSF managed beans and EJB for some business logic. I'm using JSF 1.2, JBoss 5 and java 1.6

My managed bean:

@ManagedBean(name = "managedBean")
@SessionScoped
public class MyManagedBean implements Serializable {
   @EJB(mappedName = "ejbBean")
   public MyEjbBean ejbBean;
   ....
}

EJB bean:

@Singleton(name = "ejbBean")
public class MyEjbBean {
   ....
}

Page not rendered, error:

javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: ejb not bound]

What am I doing wrong?


Solution

  • JBoss 5 doesn't support @Singleton EJB (added in EJB3.1 spec), you can use the JBoss @Service annotation to create a singleton.

    See the instructions here.