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)
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;
}
}