雷林鹏分享:EJB JNDI绑定

  JNDI代表Java命名和目录接口。它是一组API和服务接口。基于Java的应用程序使用JNDI命名和目录服务。在EJB的背景下,有两个方面。

  Binding - 这指的是以后可以使用一个EJB对象分配一个名称。

  Lookup - 这指的是寻找并获得EJB对象。

  在JBoss中,会话bean绑定到JNDI,默认情况下有以下格式。

  local - ejb-name/local

  remote - ejb-name/remote

  情况下,EJB捆绑在一起 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 bookShelf;

  public LibrarySessionBean(){

  bookShelf = new ArrayList();

  }

  public void addBook(String bookName) {

  bookShelf.add(bookName);

  }

  public List 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

  ...

  重复上述步骤,为远程和检查结果。(编辑:雷林鹏 来源:网络|侵删)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章