0

I have created a Java EE application with an EJB module and a web module in NetBeans. The business logic resides in EJBs inside the EJB module. Is it possible for managed beans of the web module to access the EJBs inside the EJB module? How?

(JDK 1.7, Java EE 6, Glassfish 3.1.2.2, NetBeans IDE 7.2)

Arash Shahkar
  • 655
  • 3
  • 12
  • 24

1 Answers1

1

You typically access an EJB from a managed bean using injection.

The exampe below shows a managed bean named ExampleManagedBean using the EJB annotation to inject a stateless session bean that implements an interface named CustomerBeanLocal.

class ExampleManagedBean {

    @EJB
    CustomerBeanLocal customerBean;

    public String testStuff() {
        int custCount = customerBean.getCustomerCount();
        System.out.println("Number of customers: " + custCount);
        return null;
    }

}
jahroy
  • 22,322
  • 9
  • 59
  • 108
  • Thank you. I'm actually dealing with another problem (mentioned @ http://stackoverflow.com/questions/12185894) and the misleading error message made me to wonder if I'm thinking wrong. – Arash Shahkar Aug 29 '12 at 22:17