Java Reference
In-Depth Information
Note
If you are planning to expose your EJB to local clients only (for example, to a
servlet), you can leave out the remote interface definition and simply annotate
your bean with @Stateless . The application server will create a no-inter-
face view of your session bean, which can safely be injected into your local cli-
ents such as servlets or other EJBs.
Adding a stateful bean
In order to control how much money our customer has got in his pocket, we would
need a session-aware component. Turning a Java class into a stateful session bean
is just a matter of adding an @Stateful annotation on top of it, as in our example
class com.packtpub.as7development.chapter3.ejb.TheatreBooker .
@Stateful
@Remote(TheatreBooker.class)
public class TheatreBookerBean implements
TheatreBooker {
private static final Logger logger =
Logger.getLogger(TheatreBookerBean.class);
int money;
@EJB TheatreBox theatreBox;
@PostConstruct
public void createCustomer() {
this.money=100;
}
@Override
public String bookSeat(int seatId) throws
SeatBookedException, NotEnoughMoneyException {
Seat seat =
Search WWH ::




Custom Search