Java Reference
In-Depth Information
3.2.5. Bean business interfaces
Clients of session beans have three different ways of invoking these beans. The first is
through the local interface within the same JVM. The second is through a remote interface
using RMI. The third way that stateless session beans can be invoked is via SOAP or REST
web services. The same session bean may be accessed by any number of these methods.
These three methods of accessing a stateless session bean are denoted using annotations.
Each of these three annotations must be placed on an interface that the bean then imple-
ments. Let's take a look at these annotations in more detail.
Local interface
A local interface is designed for clients of a stateless session bean collocated in the same
container (JVM) instance. You designate an interface as a local business interface by us-
ing the @Local annotation. The following code could be a local interface for the De-
faultBidService class in listing 3.1 :
@Local
public interface BidLocalService {
void addBid(Bid bid);
void cancelBid(Bid bid);
List<Bid> getBids(Item item);
}
Local interfaces are the easiest to define and use. They're also by far the most common
type of EJB interface and are the default type of interface for EJBs. This means that you
can omit the @Local annotation and the interface will still be treated as a local interface.
Note that in EJB 3.1 it's not necessary to define a local interface. You can't define a bean
interface at all; instead, you access the bean by its implementation class directly. For ex-
ample, you can redefine the BidService and remove all interfaces as follows:
@Stateless
public class BidService {
...
@PostConstruct
public void initialize() {
...
}
public void addBid(Bid bid) {
...
}
 
Search WWH ::




Custom Search