EJBJNDI綁定
JNDI代表Java命名和目錄接口。它是一組API和服務接口。基於Java的應用程序使用JNDI命名和目錄服務。在EJB的背景下,有兩個方面。
Binding - 這指的是以後可以使用一個EJB對象分配一個名稱。
Lookup - 這指的是尋找並獲得EJB對象。
在JBoss中,會話bean綁定到JNDI,默認情況下有以下格式。
local - ejb-name/local
remote - ejb-name/remote
情況下,EJB捆綁在一起
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
...
重複上述步驟,爲遠程和檢查結果。