发布于 2015-06-07 01:08:22 | 231 次阅读 | 评论: 0 | 来源: 网友投递

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
...

重复上述步骤,为远程和检查结果。

 

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务