0 Replies Latest reply on Jun 15, 2011 1:09 AM by Alexander Hartner

    Inherit @Resources fails

    Alexander Hartner Expert

      I would like to enherit common resources from an abstract superclass

       

       

      public abstract class AbstractManagedBean {
       @Resource(name = "jms/ConnectionFactory")
       protected ConnectionFactory m_factory;
       @Resource(name = "topic/abc/ConsoleMessages")
       protected Topic m_consoleMessagesTopic;
      }
      

       

       

      In the ejb-jar.xml and jboss.xml files I have added the appropriate declarations for all concrete subclasses of this class.

       


      ejb-jar.xml

      <!-- JobRequest Listener MDB -->
      <message-driven>
       <ejb-name>JobRequestListener</ejb-name>
       <ejb-class>com.abc.backend.jobs.JobRequestListener</ejb-class>
       <message-destination-link>JobRequests</message-destination-link>
       <!--Inherited From AbstractManagedBean -->
       <resource-ref>
       <res-ref-name>jms/ConnectionFactory</res-ref-name>
       <res-type>javax.jms.ConnectionFactory</res-type>
       <res-auth>Container</res-auth>
       </resource-ref>
       <message-destination-ref>
       <message-destination-ref-name>topic/abc/ConsoleMessages</message-destination-ref-name>
       <message-destination-type>javax.jms.Topic</message-destination-type>
       <message-destination-usage>Produces</message-destination-usage>
       <message-destination-link>ConsoleMessages</message-destination-link>
       </message-destination-ref>
       <!--Local Resources -->
      </message-driven>
      

       

       


      jboss.xml

      <!-- Job Request Listener MDB -->
      <message-driven>
       <ejb-name>JobRequestListener</ejb-name>
       <destination-jndi-name>queue/abc/JobRequests</destination-jndi-name>
       <!--Inherited From AbstractManagedBean -->
       <resource-ref>
       <res-ref-name>jms/ConnectionFactory</res-ref-name>
       <jndi-name>java:/JmsXA</jndi-name>
       </resource-ref>
       <message-destination-ref>
       <message-destination-ref-name>topic/abc/ConsoleMessages</message-destination-ref-name>
       <message-destination-type>javax.jms.Topic</message-destination-type>
       <message-destination-usage>Produces</message-destination-usage>
       <message-destination-link>ConsoleMessages</message-destination-link>
       <jndi-name>jnp://localhost:1100/topic/abc/ConsoleMessages</jndi-name>
       </message-destination-ref>
       <!--Local Resources -->
      </message-driven>
      

       

       

      However during deployment the following errors are reported. Any ideas what I have to add to the deployment descriptors to get this working. Since it's an abstract bean it doesn't seem to make sense to add it.

       

      I have already tried changing the @Resource annotation to use mappedName and this resolves the problem, however I need to defer the mapping to the "real" JNDI name to the deployment descriptor, as "java:/JmsXA" only works with JBoss and not other application servers.

       

       


      java.lang.RuntimeException: You did not specify a @Resource.mappedName() on protected javax.jms.Topic com.abc.backend.AbstractManagedBean.m_consoleMessagesTopic and there is no binding for enc name env/topic/abc/ConsoleMessages in XML
      at org.jboss.injection.ResourceHandler.handlePropertyAnnotation(ResourceHandler.java:506)
      at org.jboss.injection.ResourceHandler.handleFieldAnnotations(ResourceHandler.java:325)
      at org.jboss.injection.InjectionUtil.processFieldAnnotations(InjectionUtil.java:137)
      at org.jboss.injection.InjectionUtil.processFieldAnnotations(InjectionUtil.java:143)
      at org.jboss.injection.InjectionUtil.processAnnotations(InjectionUtil.java:174)
      at org.jboss.ejb3.EJBContainer.processMetadata(EJBContainer.java:358)
      at org.jboss.ejb3.SessionContainer.processMetadata(SessionContainer.java:140)
      at org.jboss.ejb3.Ejb3Deployment.processEJBContainerMetadata(Ejb3Deployment.java:292)
      at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:356)
      at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
      at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
      at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
      at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
      at $Proxy0.start(Unknown Source)
      at org.jboss.system.ServiceController.start(ServiceController.java:417)
      at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
      at $Proxy33.start(Unknown Source)
      at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:512)
      at sun.reflect.GeneratedMethodAccessor247.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
      at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
      at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
      at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
      at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
      at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
      at $Proxy34.start(Unknown Source)
      at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
      at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
      at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
      at $Proxy65.deploy(Unknown Source)
      at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
      at org.jboss.ha.framework.server.FarmMemberService.deploy(FarmMemberService.java:412)
      at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
      14:28:26,541 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.2.2.GA/server/all/tmp/deploy/tmp60776ABCEJB.ear-contents/ABCEJB.jar
      14:28:26,541 INFO [STDOUT] Busy