Monday, March 1, 2010

EJB 3.0 super fast tutorial

Create an EJB project PVEJB30Test.

Create an Interface- this will be the remote interface of your Stateless EJB:

package com.pierre;

public interface Messenger {
    String getMessage(String name);
}


Create the Implementation:

package com.pierre;

import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless
@Remote(Messenger.class)
public class MessengerSB implements Messenger {
   
    public String getMessage(String name) {
        return "Ciao " + name;
    }
   
}



Deploy your project to the WebLogic Server:

You will magically get this:

Application Name: PVEJB30Test
EJB Module Name:PVEJB30Test
Bean Name: MessengerSB


Easy. It could be easier (for instance, not having to create the Interface) but it's easy.


In the JNDI tree you will get:


PVEJB30TestPVEJB30TestMessengerSB_Home (=
weblogic.ejb.container.internal.StatelessEJBHomeImpl
)
 
and
PVEJB30TestPVEJB30TestMessengerSB_Messenger (=
com.pierre.MessengerSB_hodc5c_MessengerImpl_1030_WLStub
)
 
 
If you specify
@Stateless(mappedName="Pippo")
you will get this binding:
Pippo#com.pierre.Messenger
 
 


No comments: