JNDI代表Java命名和目錄介面。它是一組API和服務介面。基於Java的應用程式使用JNDI命名和目錄服務。在EJB的背景下,有兩個方面。
Binding - 這指的是以後可以使用一個EJB物件分配一個名稱。
Lookup - 這指的是尋找並獲得EJB物件。
在JBoss中,對談bean系結到JNDI,預設情況下有以下格式。
local - ejb-name/local
remote - ejb-name/remote
情況下,EJB捆綁在一起<application-name> ear檔案預設格式如下。
local - application-name/ejb-name/local
remote - application-name/ejb-name/remote
請參閱EJB - 建立應用本章的JBoss的控制台輸出。
JBoss應用伺服器的紀錄檔輸出
... 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 ...
以下註釋可以用來客製化預設JNDI系結。
local - org.jboss.ejb3.LocalBinding
remote - org.jboss.ejb3.RemoteBindings
更新LibrarySessionBean.java。請參閱EJB - 建立應用程式一章
LibrarySessionBean
package com.tutorialspoint.stateless; import java.util.ArrayList; import java.util.List; import javax.ejb.Stateless; @Stateless @LocalBinding(jndiBinding="tutorialsPoint/librarySession") public class LibrarySessionBean implements LibrarySessionBeanLocal { List<String> bookShelf; public LibrarySessionBean(){ bookShelf = new ArrayList<String>(); } public void addBook(String bookName) { bookShelf.add(bookName); } public List<String> getBooks() { return bookShelf; } }
LibrarySessionBeanLocal
package com.tutorialspoint.stateless; import java.util.List; import javax.ejb.Local; @Local public interface LibrarySessionBeanLocal { void addBook(String bookName); List getBooks(); }
構建專案。將應用程式部署在JBoss在JBoss控制台驗證下面的輸出。
... 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/librarySession - EJB3.x Default Local Business Interface tutorialsPoint/librarySession-com.tutorialspoint.stateless.LibrarySessionBeanLocal - EJB3.x Local Business Interface ...
重複上述步驟,為遠端和檢查結果。