ejb31 tutorial example - Creating EJB 3.1 Stateless Session Bean using JBoss 6.1 Example

Creating EJB 3.1 Stateless Session Bean using JBoss 6.1 Example

Posted on

ejb31 tutorial example - Creating EJB 3.1 Stateless Session Bean using JBoss 6.1 ExampleStateless session beans are stateless in nature, in different phrases it doesn’t keep in mind its earlier invocations. A person will name the bean and the bean will return a consequence. A stateless bean shouldn’t be good for sustaining the state of an interactive session similar to required to keep up a listing of purchases. Nonetheless, it’s helpful for one-time calculations

This tutorial demonstrates creating EJB utilizing @Stateless annotation. The mappedName attribute of @Stateless annotation describe a person friendly-name used to invoke bean.

A session bean may have a neighborhood, distant and no-interface consumer view. The interface used determines the intent and scope of the bean. The no-interface view is new to EJB 3.1. This strategy permits the developer to make use of EJB with out having to declare a enterprise interface.

Accessing a Session Bean utilizing Dependency Injection

There are two strategies for having access to an EJB:

  • Dependency Injection (DI)
  • Java Naming and Listing Service (JNDI).

DI is the simplest after we can use it, however JNDI can be utilized in locations the place DI shouldn’t be supported. We are going to take a look at each of those approaches. Nonetheless, EJBs shouldn’t be created utilizing the Java new key phrase.

If the EJB is created utilizing this key phrase, then it’ll not be an EJB however slightly a daily object. It won’t be able to reap the benefits of the assist offered by the EJB container.

To make use of DI, use @EJB annotation. This can inject EJB reference into our software. Following code show use of @EJB.

Now create a ear file containing Servlet, EJB and deploy it on JBoss’s root listing. Output shall be much like following display shot.

EJB 3.1 Stateless Session Bean1 - Creating EJB 3.1 Stateless Session Bean using JBoss 6.1 Example

Download Source

Supply techzoo.org