Creating session beans using local business interface

Business interface for the EJB is a simple Java interface annotated either with @Remote or @Local. Therefore, we can create a local interface for a student bean as follows:

import java.util.List; 
import javax.ejb.Local; 
 
@Local 
public interface StudentLocal { 
  public List<Course> getCourses(); 
} 

Furthermore, we can implement a session bean as follows:

import java.util.List; 
import javax.ejb.Local; 
import javax.ejb.Stateful; 
 
@Stateful 
@Local 
public class Student implements StudentLocal { 
  @Override 
  public List<CourseDTO> getCourses() { 
    //get courses are return 
... 
  } 
} 

The client can access the Student EJB only through the local interface:

import javax.ejb.EJB; import javax.faces.bean.ManagedBean; ...

Get Java EE 8 Development with Eclipse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.