geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tomasz Mazan <win...@wp.pl>
Subject Re: Problem with referencing to beans from other ejb-jars
Date Thu, 20 Sep 2007 22:37:21 GMT


Tomasz Mazan wrote:
> 
> Hello
> 
> I got deployed module A (JAR) and application B (EAR). 
> 
> A) Contains stateless bean
> 
> @Stateless(name = "JmsDispatcherGate")
> public class JmsDispatcherGateImpl implements DispatcherGateLocal,
> DispatcherGateRemote {
> 
> and - of course - necessary interfaces.
> 
> ejb-jar.xml does'nt contain interesting content,
> openejb-jar.xml contains module description
>     <sys:moduleId>
>       <sys:groupId>myejbmodule</sys:groupId>
>       <sys:artifactId>Dispatcher</sys:artifactId>
>       <sys:version>1.0</sys:version>
>       <sys:type>jar</sys:type>
>     </sys:moduleId>
> 
> B) Application contains two ejb-jars with beans
> 
> geronimo-application.xml contains
>         <dependencies>
>         	<dependency>
>         		<groupId>myejbmodule</groupId>
>         		<artifactId>Dispatcher</artifactId>
>         		<version>1.0</version>
>         		<type>jar</type>
>         	</dependency>
>         </dependencies>
> 
> and one of B-module has openejb-jar.xml with similar dependencie's
> definition.
> Bean in B-module references to bean from A (EJB) using code below:
> 
> 	@EJB(name = "JmsDispatcherGate")
> 	private DispatcherGateLocal dispatcherGate;
> 
> Problem occurs on deploying B-application (EAR) while A (EJB) is correctly
> deployed and Geronimo Console JNDI Viewer show JmsDispatcherGate bean. I
> tried to use Remote interface - with no special difference.
> 
> Exception stacktrace:
> 15:31:18,812 FATAL [startup] Cannot find bean "JmsDispatcherGate"
> referenced by bean "CoreManagerLocal".
> 15:31:18,812 ERROR [Deployer] Deployment failed due to 
> org.apache.geronimo.common.DeploymentException:
> org.apache.openejb.OpenEJBException: Cannot find bean "JmsDispatcherGate"
> referenced by bean "CoreManagerLocal".
> 	at
> org.apache.geronimo.openejb.deployment.EjbModuleBuilder.getEjbJarInfo(EjbModuleBuilder.java:530)
> 	at
> org.apache.geronimo.openejb.deployment.EjbModuleBuilder.initContext(EjbModuleBuilder.java:437)
> 	at
> org.apache.geronimo.openejb.deployment.EjbModuleBuilder$$FastClassByCGLIB$$cd80af20.invoke(<generated>)
> 	at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
> 	at
> org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38)
> 	at
> org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:124)
> 	at
> org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:830)
> 	at
> org.apache.geronimo.gbean.runtime.RawInvoker.invoke(RawInvoker.java:57)
> 	at
> org.apache.geronimo.kernel.basic.RawOperationInvoker.invoke(RawOperationInvoker.java:35)
> 	at
> org.apache.geronimo.kernel.basic.ProxyMethodInterceptor.intercept(ProxyMethodInterceptor.java:96)
> 	at
> org.apache.geronimo.j2ee.deployment.ModuleBuilder$$EnhancerByCGLIB$$dc485bed.initContext(<generated>)
> 	at
> org.apache.geronimo.j2ee.deployment.EARConfigBuilder.buildConfiguration(EARConfigBuilder.java:576)
> 	at
> org.apache.geronimo.j2ee.deployment.EARConfigBuilder$$FastClassByCGLIB$$38e56ec6.invoke(<generated>)
> 	at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
> 	at
> org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38)
> 	at
> org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:124)
> 	at
> org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:830)
> 	at
> org.apache.geronimo.gbean.runtime.RawInvoker.invoke(RawInvoker.java:57)
> 	at
> org.apache.geronimo.kernel.basic.RawOperationInvoker.invoke(RawOperationInvoker.java:35)
> 	at
> org.apache.geronimo.kernel.basic.ProxyMethodInterceptor.intercept(ProxyMethodInterceptor.java:96)
> 	at
> org.apache.geronimo.j2ee.deployment.CorbaGBeanNameSource$$EnhancerByCGLIB$$1375d602.buildConfiguration(<generated>)
> 	at org.apache.geronimo.deployment.Deployer.deploy(Deployer.java:304)
> 	at org.apache.geronimo.deployment.Deployer.deploy(Deployer.java:126)
> 	at
> org.apache.geronimo.deployment.Deployer$$FastClassByCGLIB$$734a235d.invoke(<generated>)
> 	at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
> 	at
> org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38)
> 	at
> org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:124)
> 	at
> org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:865)
> 	at
> org.apache.geronimo.kernel.basic.BasicKernel.invoke(BasicKernel.java:239)
> 	at org.apache.geronimo.kernel.KernelGBean.invoke(KernelGBean.java:342)
> 	at
> org.apache.geronimo.kernel.KernelGBean$$FastClassByCGLIB$$1cccefc9.invoke(<generated>)
> 	at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
> 	at
> org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38)
> 	at
> org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:124)
> 	at
> org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:865)
> 	at
> org.apache.geronimo.kernel.basic.BasicKernel.invoke(BasicKernel.java:239)
> 	at
> org.apache.geronimo.system.jmx.MBeanGBeanBridge.invoke(MBeanGBeanBridge.java:168)
> 	at
> com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(DynamicMetaDataImpl.java:213)
> 	at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:220)
> 	at
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:815)
> 	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:784)
> 	at
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1408)
> 	at
> javax.management.remote.rmi.RMIConnectionImpl.access$100(RMIConnectionImpl.java:81)
> 	at
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1245)
> 	at java.security.AccessController.doPrivileged(Native Method)
> 	at
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1348)
> 	at
> javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:782)
> 	at sun.reflect.GeneratedMethodAccessor217.invoke(Unknown Source)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:585)
> 	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
> 	at sun.rmi.transport.Transport$1.run(Transport.java:153)
> 	at java.security.AccessController.doPrivileged(Native Method)
> 	at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
> 	at
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
> 	at
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
> 	at java.lang.Thread.run(Thread.java:595)
> Caused by: org.apache.openejb.OpenEJBException: Cannot find bean
> "JmsDispatcherGate" referenced by bean "CoreManagerLocal".
> 	at
> org.apache.openejb.config.JndiEncInfoBuilder.buildEjbLocalRefInfos(JndiEncInfoBuilder.java:371)
> 	at
> org.apache.openejb.config.JndiEncInfoBuilder.build(JndiEncInfoBuilder.java:245)
> 	at
> org.apache.openejb.config.JndiEncInfoBuilder.initJndiReferences(JndiEncInfoBuilder.java:166)
> 	at
> org.apache.openejb.config.JndiEncInfoBuilder.initJndiReferences(JndiEncInfoBuilder.java:102)
> 	at
> org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:340)
> 	at
> org.apache.geronimo.openejb.OpenEjbSystemGBean.configureApplication(OpenEjbSystemGBean.java:303)
> 	at
> org.apache.geronimo.openejb.OpenEjbSystemGBean$$FastClassByCGLIB$$5005cdd0.invoke(<generated>)
> 	at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
> 	at
> org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38)
> 	at
> org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:124)
> 	at
> org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:830)
> 	at
> org.apache.geronimo.gbean.runtime.RawInvoker.invoke(RawInvoker.java:57)
> 	at
> org.apache.geronimo.kernel.basic.RawOperationInvoker.invoke(RawOperationInvoker.java:35)
> 	at
> org.apache.geronimo.kernel.basic.ProxyMethodInterceptor.intercept(ProxyMethodInterceptor.java:96)
> 	at
> org.apache.geronimo.openejb.OpenEjbSystem$$EnhancerByCGLIB$$e2a54c40.configureApplication(<generated>)
> 	at
> org.apache.geronimo.openejb.deployment.EjbModuleBuilder.getEjbJarInfo(EjbModuleBuilder.java:515)
> 	... 56 more
> 
> Any idea what goes wrong and how to make it working?
> 
> tia
> Beniamin
> 

Thanks to David Blevins and David Jenks, I got solution for my references.
All, that I need is one additional attribute "mappedName" with value set to
deploymentId of Bean within A-jar.

1st approach

Annotation for bean reference within B application EAR should looks like:

        @EJB(mappedName="deploymentId")
        private DispatcherGateLocal dispatcherGate; 

where deployment id quals  "ArtifactId/beanName" - here
"myejbmodule/JmsDispatcherGate"

I can use Local interface cause EAR B-application descriptor contains
dependency to A Ejb-jar. In other case it would be necessary to use Remote
interface instead of Local.

2nd approach
Alternative is to modify openejb-jar.xml like shown below:

Left java-annotation like usual for reference to another bean (both in the
same EAR/JAR)
        
        @EJB(name="_REF_NAME_")
        private DispatcherGateLocal dispatcherGate; 

and insert into openejb-jar.xml:

<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>mygroup1</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>mygroup2</sys:groupId>
        		<sys:artifactId>OUTER_MODULE</sys:artifactId>
        		<sys:version>1.0</sys:version>
        		<sys:type>jar</sys:type>
        	</sys:dependency>
        </sys:dependencies>
  </sys:environment>
  <enterprise-beans>
  	<session>
        <!-- name of bean that wants to use bean from another jar -->
    	<ejb-name>MyServiceBean</ejb-name>
		<ejb-ref>
			<!-- @EJB(name="REF_NAME") DispatcherGateRemote dispatcherGate; -->
			<ref-name>REF_NAME</ref-name>
            <nam:pattern
xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2">
               	<nam:artifactId>OUTER_MODULE</nam:artifactId>
               	<nam:name>NAME_OF_REFERED_BEAN</nam:name>
            </nam:pattern>
		</ejb-ref>
    </session>
  </enterprise-beans>
</openejb-jar>

3rd approach
It's very similar to 2nd, but you don't have to use name attribute in @EJB
annotation, so java code (of bean i.e. my.package.SuperServiceBean) looks
like

        @EJB
        private DispatcherGateLocal dispatcherGate; 

and corresponding openejb-jar.xml:

<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>mygroup1</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>mygroup2</sys:groupId>
        		<sys:artifactId>OUTER_MODULE</sys:artifactId>
        		<sys:version>1.0</sys:version>
        		<sys:type>jar</sys:type>
        	</sys:dependency>
        </sys:dependencies>
  </sys:environment>
  <enterprise-beans>
  	<session>
        <!-- name of bean that wants to use bean from another jar -->
    	<ejb-name>MyServiceBean</ejb-name>
		<ejb-ref>
			<!-- @EJB DispatcherGateRemote dispatcherGate; -->
			<ref-name>my.package.SuperServiceBean/dispatcherGate</ref-name>
            <nam:pattern
xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2">
               	<nam:artifactId>OUTER_MODULE</nam:artifactId>
               	<nam:name>NAME_OF_REFERED_BEAN</nam:name>
            </nam:pattern>
		</ejb-ref>
    </session>
  </enterprise-beans>
</openejb-jar>

I think it's obvious you have to replace CAPITAL strings with suitable
values.
Maybe not obviuos but intuitive is that the best approach is no 2.

-- 
View this message in context: http://www.nabble.com/Problem-with-referencing-to-beans-from-other-ejb-jars-tf4435740s134.html#a12787921
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Mime
View raw message