The HelloWorld bean is divided in 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 doesn't
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 code of the EJB has been written, it's the time to define the EJB application.
This bean will be a stateless session bean, so the class will be annotated with @Stateless annotation.
And the interface needs to be available for remote clients, so it will be a remote interface. This is done by using the @Remote annotation.
package org.objectweb.easybeans.tutorial.helloworld; /** * 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. |