How do I create a stateless session bean with EJB 3.0?

Byron Tymvios

To create a stateless session bean you need to make use of the @Stateless annotation. You place the annotation on the line before the class declaration. You will also need to implement an interface to allow either local or remote access to the beans methods and to define the methods.

Here is the interface, I have declared as remote with the @Remote annotation.

import javax.ejb.Remote;

@Remote
public interface StatelessInterface{
    public String someMethod();
}


Here is the bean with the method implemented.
import javax.ejb.Stateless;

@Stateless
public class MyStatelessSessionBean implements StatelessInterface{
    private int someInt = -1;

    public void MyStatelessSessionBean(){
    }

    public String someMethod(){
        return "My Stateless Session Bean";
    }
}

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact