Creating a Stateful Session Bean

Business Interface

Create the bean interface and mark it either as @Remote or @Local. Stateful cannot have web service client view.

Remote Interface

import javax.ejb.Remote;

@Remote
public interface HelloWorld {
	String sayHello();
}

Local Interface

import javax.ejb.Local;

@Local
public interface HelloWorld {
	String sayHello();
}

Bean implementation class

Create a class which implements the business interface. Mark this class as stateful session bean using @Stateful annotation before the class signature.

import javax.ejb.Stateful;
@Stateful
public class HelloWorldBean implements HelloWorld {
	public HelloWorldBean() {
    	}

	public String sayHello() {
		return "Hello World !!!";
	}
}

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.