Java Reference
In-Depth Information
With multiple beans now implementing the AccountLocal interface, you need to give
the @EJB annotation a little help so the container knows which implementation should be
injected:
@EJB(beanName="accountByActiveDirectory")
AccountLocal accountInfo;
In this example, the container detects the @EJB annotation, and the value for beanName
narrows down what implementation to inject. The container will find the bean with the
name accountByActiveDirectory , check that the bean implements the Accoun-
tLocal interface, and inject an instance of the AccountByActiveDirectoryEjb
into the accountInfo variable.
Injection using beanInterface
In many cases, you'll have a common interface that you'll want to expose locally and re-
motely. Your classes may resemble this structure:
public interface AccountServices {
public Account getAccount(String accountId);
}
@Local
public interface AccountLocal extends AccountServices {}
@Remote
public interface AccountRemote extends AccountServices {}
@Stateless
public class AccountEjb implements AccountLocal, AccountRemote {. . .}
The @EJB annotation is configured using the beanInterface property to tell the con-
tainer to inject either the remote or the local interface:
@EJB(beanInterface="AccountLocal.class")
AccountServices accountServices;
In this example, the container detects the @EJB annotation, and the value for beanIn-
terface narrows down what to inject. The container will find a bean with Accoun-
tLocal.class as an interface. When the bean is injected, it's type-casted to Accoun-
tServices . Injecting like this tells the container you want to use a local bean but interact
Search WWH ::




Custom Search