English 中文(简体)
EJB - JNDI Bindings
  • 时间:2024-12-22

EJB - JNDI Bindings


Previous Page Next Page  

JNDI stands for Java Naming and Directory Interface. It is a set of API and service interfaces. Java based apppcations use JNDI for naming and directory services. In context of EJB, there are two terms.

    Binding − This refers to assigning a name to an EJB object, which can be used later.

    Lookup − This refers to looking up and getting an object of EJB.

In Jboss, session beans are bound in JNDI in the following format by default.

    local − EJB-name/local

    remote − EJB-name/remote

In case, EJB are bundled with <apppcation-name>.ear file, then default format is as following −

    local − apppcation-name/ejb-name/local

    remote − apppcation-name/ejb-name/remote

Example of Default Binding

Refer to EJB - Create Apppcation chapter s JBoss console output.

JBoss Apppcation Server Log Output

...
16:30:02,723 INFO  [SessionSpecContainer] Starting jboss.j2ee:jar=EjbComponent.jar,name=LibrarySessionBean,service=EJB3
16:30:02,723 INFO  [EJBContainer] STARTED EJB: com.tutorialspoint.stateless.LibrarySessionBean ejbName: LibrarySessionBean
16:30:02,731 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

   LibrarySessionBean/remote - EJB3.x Default Remote Business Interface
   LibrarySessionBean/remote-com.tutorialspoint.stateless.LibrarySessionBeanRemote - EJB3.x Remote Business Interface
...

Customized Binding

Following annotations can be used to customize the default JNDI bindings −

    local − org.jboss.ejb3.LocalBinding

    remote − org.jboss.ejb3.RemoteBindings

Update LibrarySessionBean.java. Refer to EJB - Create Apppcation chapter.

LibrarySessionBean

package com.tutorialspoint.stateless;
 
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
 
@Stateless
@LocalBinding(jndiBinding="tutorialsPoint/pbrarySession")
pubpc class LibrarySessionBean implements LibrarySessionBeanLocal {
    
    List<String> bookShelf;    
    
    pubpc LibrarySessionBean() {
       bookShelf = new ArrayList<String>();
    }
    
    pubpc void addBook(String bookName) {
       bookShelf.add(bookName);
    }    
 
    pubpc List<String> getBooks() {
        return bookShelf;
    }
}

LibrarySessionBeanLocal

package com.tutorialspoint.stateless;
 
import java.util.List;
import javax.ejb.Local;
 
@Local
pubpc interface LibrarySessionBeanLocal {
 
    void addBook(String bookName);
 
    List getBooks();
    
}

Build the project, deploy the apppcation on Jboss, and verify the following output in Jboss console −

...
16:30:02,723 INFO  [SessionSpecContainer] Starting jboss.j2ee:jar=EjbComponent.jar,name=LibrarySessionBean,service=EJB3
16:30:02,723 INFO  [EJBContainer] STARTED EJB: com.tutorialspoint.stateless.LibrarySessionBean ejbName: LibrarySessionBean
16:30:02,731 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

   tutorialsPoint/pbrarySession - EJB3.x Default Local Business Interface
   tutorialsPoint/pbrarySession-com.tutorialspoint.stateless.LibrarySessionBeanLocal - EJB3.x Local Business Interface
...
Advertisements