I have a stateless session bean, but I want to add a reference to another bean in order to do some process. So if I add reference to another bean it shows up at instance level variable like this,
@Stateless
public class AccountFacade extends AbstractFacade<Account> implements AccountFacadeRemote {
@EJB
private BillerFacadeRemote billerFacade;
public AccountFacade() {
super(Account.class);
}
... all other methods...
}
Now, by definition stateless bean should not have any instance level variables. So I am quite confuse about where to put this private BillerFacadeRemote billerFacade;
?
Your code is fine.
The @EJB annotation is injecting the bean into your class, and the application server manages its lifetime.
I recommend reading, or skimming the pretty long Java EE tutorial.
"The EJB container typically creates and maintains a pool of stateless session beans, beginning the stateless session bean’s lifecycle. The container performs any dependency injection and then invokes the method annotated @PostConstruct, if it exists. The bean is now ready to have its business methods invoked by a client."