Java EE 7 SDK 

Samples Main Page

The Stateless Bean EJB Sample Application (EJB Module)

This sample is a simple EJB stateless session bean with a remote business interface.

Description

This sample application consists of two parts: an EJB module (this project) and a test client. The rest of this document describes the EJB module.

Business Interface

The stateless session bean has a remote business interface with a single business method:

import javax.ejb.Remote;

@Remote
public interface StatelessSession {

    public String hello();

}
				

Note: Unlike in earlier versions of EJB, the remote interface is not required to extend java.rmi. The remote interface and its business methods are not required to throw java.rmi.RemoteException.

The @javax.ejb.Remote annotation designates the business interface as a remote business interface.

Stateless Session Bean

The bean implementation is as follows:

@Stateless
public class StatelessSessionBean implements StatelessSession {
	
	public String hello() {
		return "hello, world!\n";
	}
	
}
        

@javax.ejb.Stateless is a component-defining annotation that designates this class as the bean class for a stateless session bean.

Deployment Descripton

The deployment descriptor is no longer required. The two Java files above are sufficient to completely describe this stateless session bean.

Key Features

This sample demonstrates the following key features of EJBs:

Building, Deploying, and Running the Application

Perform the following steps to build, deploy, and run the application:

  1. Set up your build environment and configure the application server with which the build system has to work by following the common build instructions.
  2. app_dir is the sample application base directory: samples_install_dir/javaee7/ejb/hello-stateless-ejb/hello-stateless-ejb-bean.
  3. Change directory to app_dir.
  4. Build, deploy, and run the sample application using the run outcome.

    mvn clean verify cargo:run

  5. Use the clean outcome to undeploy the sample application and to remove the temporary directories such as target.

    mvn clean

Troubleshooting

If you have problems when running the application, refer to the troubleshooting document.



Copyright © 1997-2013 Oracle and/or its affiliates. All rights reserved.