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

此生再无相见时 提交于 2020-01-02 02:43:17

问题


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.


回答1:


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;



回答2:


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.




回答3:


It is very AS-specific.

JBoss 7+ makes it possible if you:

  1. Define outbound-socket-binding, security-realm and remote-outbound-connection in the standalone file (all referring to the remote JBoss instance).
  2. Add a jboss-ejb-client.xml to the META-INF folder of your packaged application, with a remoting-ejb-receiver for every connection needed by the application.
  3. Inject the remote EJB with@EJB(lookup = "<jndi_name>")

Let me know if further details are needed.

Give a look at:

  • JBoss configuration for remote connections
  • An article about Glassfish-Glassfish remote connections


来源:https://stackoverflow.com/questions/1560335/is-it-possible-to-use-ejb-annotation-to-inject-ejbs-through-different-servers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!