07 November 2011

JBoss: Injecting remote EJB from one container to another

These methods tested on JBoss AS 6.1.0.

Assume we have two EJBs with full qualified classnames "com.foo.ejb1.Bean1" and "com.foo.ejb2.Bean2". Second EJB deployed on remote JBoss and have remote interface "com.foo.ejb2.Bean2Remote".

Method one, using only EJB annotation:

public class Bean1 implements ...
private Bean2Remote b2;

We use "EJB" annotation with "lookup" element. For JBoss 6, it contains JNP URL to remote EJB, where "hostname" is the host name or IP address of remote JBoss server, and "Bean2" is the name of remote EJB.

Method two, using EJB annotation and ejb-jar configuration: