我有2个会话bean,OrderBean和InventoryBean,它们部署在不同的weblogic服务器上.
OrderBean需要访问InventoryBean以检查供应是否足够.
目前,我使用JNDI查找找到InventoryBean,它工作正常.
现在我想知道是否可以使用@EJB通过在xml或其他地方提供JNDI名称和URL来注入InventoryBean.
最后我找到了一种方法来做到这一点.
一世.在weblogic服务器上配置外部JNDI,并将远程EJB链接到本地JNDI名称.
例如:
Local JNDI: InventoryBean#com.pkg.InventoryBean (MAPPEDNAME#FULLNAME) link to Remote JNDI: ServiceBean#com.pkg.InventoryBean
II.在ejb-jar.xml中配置ejb-ref
ejb-ref-name -> ejb/InventoryBean remote -> com.pkg.InventoryService mapped-name -> InventoryBean
III.在OrderBean中添加@EJB注释
@EJB(name = "ejb/InventoryBean") private InventoryService inventoryService;