The HelloWorld bean is divided into two parts: the business interface, and the class implementing this interface.
The interface declares only one method:
helloWorld()
package org.objectweb.easybeans.tutorial.helloworld;
/**
* Interface of the HelloWorld example.
* @author Florent Benoit
*/
public interface HelloWorldInterface {
/**
* Hello world.
*/
void helloWorld();
}
![]() |
Note |
|---|---|
|
Even if this interface is used as a remote interface, it does
not need to extend |
The following code implements the existing interface:
package org.objectweb.easybeans.tutorial.helloworld;
/**
* Business code for the HelloWorld interface.
* @author Florent Benoit
*/
public class HelloWorldBean implements HelloWorldInterface {
/**
* Hello world implementation.
*/
public void helloWorld() {
System.out.println("Hello world !");
}
}
![]() |
Note |
|---|---|
|
At this moment, the bean is not an EJB; this is only a class implementing an interface. |
Now that the EJB code has been written, it is time to define the EJB application.
This bean will be a stateless session bean, thus the class will be
annotated with @Stateless annotation.
In addition, the interface must be a remote interface to be
available for remote clients. This is done by using the
@Remote annotation.
package org.objectweb.easybeans.tutorial.helloworld;
import javax.ejb.Remote;
import javax.ejb.Stateless;
/**
* Business code for the HelloWorld interface.
* @author Florent Benoit
*/
@Stateless
@Remote(HelloWorldInterface.class)
public class HelloWorldBean implements HelloWorldInterface {
/**
* Hello world implementation.
*/
public void helloWorld() {
System.out.println("Hello world !");
}
}
![]() |
Note |
|---|---|
|
If a class implements a single interface, this interface is defined as a local interface by default. |