|
| Home > Apache Geronimo v3.0 > Documentation > Developing > Tutorials > Developing EJB applications > Referring to an EJB from outside its EAR |
Referring to beans from other Jar not included in the same Ear is not as simple as in case they are included in one Ear. There are three ways to accomplish this purpose.
@Stateless(name="JmsDispatcherGate") public class JmsDispatcherGateImpl implements DispatcherGateLocal, DispatcherGateRemote {
@Local public interface DispatcherGateLocal {
@Remote public interface DispatcherGateRemote {
<?xml version="1.0" encoding="UTF-8"?> <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1" xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"> <sys:environment> <sys:moduleId> <sys:groupId>my.app.dispatcher</sys:groupId> <sys:artifactId>Dispatcher</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>jar</sys:type> </sys:moduleId> </sys:environment> </openejb-jar>
package my.app.services; @Stateless(name = "Sender") public class SenderImpl { @EJB(mappedName="Dispatcher/JmsDispatcherGate") private DispatcherGateRemote dispatcherGate = null;
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1" xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"> <sys:environment> <sys:moduleId> <sys:groupId>my.app.services</sys:groupId> <sys:artifactId>Services</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>jar</sys:type> </sys:moduleId> <!-- only dependency is required --> <sys:dependencies> <sys:dependency> <sys:groupId>my.app.dispatcher</sys:groupId> <sys:artifactId>Dispatcher</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>jar</sys:type> </sys:dependency> </sys:dependencies> </sys:environment> </openejb-jar>
package my.app.services; @Stateless(name = "Sender") public class SenderImpl { @EJB(name="dispatcher") private DispatcherGateRemote dispatcherGate = null;
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1" xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"> <sys:environment> <sys:moduleId> <sys:groupId>my.app.services</sys:groupId> <sys:artifactId>Services</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>jar</sys:type> </sys:moduleId> <sys:dependencies> <sys:dependency> <sys:groupId>my.app.dispatcher</sys:groupId> <sys:artifactId>Dispatcher</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>jar</sys:type> </sys:dependency> </sys:dependencies> </sys:environment> <enterprise-beans> <session> <ejb-name>Sender</ejb-name> <ejb-ref> <!-- @EJB(name="dispatcher") DispatcherGateRemote dispatcherGateRemote; --> <ref-name>dispatcher</ref-name> <nam:pattern xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"> <nam:artifactId>Dispatcher</nam:artifactId> <nam:name>JmsDispatcherGate</nam:name> </nam:pattern> </ejb-ref> </session> </enterprise-beans> </openejb-jar>
package my.app.services; @Stateless(name = "Sender") public class SenderImpl { @EJB private DispatcherGateRemote dispatcherGate = null; ... }
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1" xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"> <sys:environment> <sys:moduleId> <sys:groupId>my.app.services</sys:groupId> <sys:artifactId>Services</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>jar</sys:type> </sys:moduleId> <sys:dependencies> <sys:dependency> <sys:groupId>my.app.dispatcher</sys:groupId> <sys:artifactId>Dispatcher</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>jar</sys:type> </sys:dependency> </sys:dependencies> </sys:environment> <enterprise-beans> <session> <ejb-name>Sender</ejb-name> <ejb-ref> <!-- @EJB DispatcherGateRemote dispatcherGateRemote; --> <ref-name>my.app.services.SenderImpl/dispatcherGate</ref-name> <nam:pattern xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"> <nam:artifactId>Dispatcher</nam:artifactId> <nam:name>JmsDispatcherGate</nam:name> </nam:pattern> </ejb-ref> </session> </enterprise-beans> </openejb-jar>
|
|
Privacy Policy - Copyright © 2003-2013, The Apache Software Foundation, Licensed under ASL 2.0. |