tags:

views:

334

answers:

2

I have 2 session beans, OrderBean and InventoryBean which are deployed at different weblogic servers.

The OrderBean needs to access the InventoryBean to check if the supply is sufficient.

Currently, I use JNDI look up to locate the InventoryBean and it works fine.

Now I'm wondering if it is possible to use @EJB to inject InventoryBean by providing the JNDI name and the URL in xml or somewhere else.

A: 

I think it is not possible through EJB annotations, but you can configure foreign JNDI on your WebLogic server and refer to your remote EJB as a local JNDI name. Though, I never tried that, but I think it should work.

Superfilin
Thanks, actually I have tried that before and it works fine just like you said.
Eric
+1  A: 

Finally I found a way to do this.

i. Configure the foreign JNDI on the weblogic server and link the remote EJB to a local JNDI name.

For example:

Local JNDI:
InventoryBean#com.pkg.InventoryBean (MAPPEDNAME#FULLNAME)
link to
Remote JNDI:
ServiceBean#com.pkg.InventoryBean 

ii. Configure ejb-ref in ejb-jar.xml

ejb-ref-name -> ejb/InventoryBean
remote -> com.pkg.InventoryService
mapped-name -> InventoryBean

iii. Add the @EJB annotation in OrderBean

@EJB(name = "ejb/InventoryBean")
private InventoryService inventoryService;
Eric