Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use @EJB annotation to inject EJBs through different servers?

Tags:

java

ejb-3.0

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.

like image 347
Eric Avatar asked Oct 13 '09 13:10

Eric


People also ask

What is the use of @EJB annotation?

The purpose of having annotations is to attach additional information in the class or a meta-data of a class within its source code. In EJB 3.0, annotations are used to describe configuration meta-data in EJB classes.

What is the difference between @EJB and @inject?

@Inject is more general than EJB and is part of CDI specification. So if you want to use @Inject, you need an implementation of it in your server. For POJOs (not EJBs) you have to use @Inject.


1 Answers

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;
like image 148
Eric Avatar answered Nov 08 '22 07:11

Eric