13 Replies Latest reply on Jan 27, 2009 8:59 AM by Andre Ehrlich

    How to inject sessionbean from sessionbean from another appl

    Kris Olszewski Newbie

      Hi,

      JBOSS 5.0.0.GA

      I'm trying to inject my sessionBean "VatCounter" into my another session bean "ComplexCounter"

      @Stateless
      class ComplexCounter implemenst ComplexCounterLocal {
      
       @EJB
       private VatCounterLocal vatCounter;
      
       ...
      
      }


      all works when "VatCounter" and "ComplexCounter" exists in the same jar file. When i put this beans in two separated jars, first jar with "VatCounter" deploys fine, but second not, :


      12:28:54,666 WARN [MappedReferenceMetaDataResolverDeployer] Unresolved references exist in JBossMetaData:[#ComplexCounter:AnnotatedEJBReferenceMetaData{name=pl.com.stream.asen2.service2.impl.ComplexCounter/vatCounter,ejb-ref-type=null,link=null,ignore-dependecy=false,mapped/jndi-name=null,resolved-jndi-name=null,beanInterface=interface pl.com.stream.asen2.service1.commons.VatCounterLocal}]
      12:28:54,667 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@22718711{vfszip:/D:/jboss-5.0.0.GA/server/default/deploy/Asen2Service2.jar}
      12:28:54,667 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@22718711{vfszip:/D:/jboss-5.0.0.GA/server/default/deploy/Asen2Service2.jar}
      12:28:54,687 WARN [EJBRemoteHandler] EJBTHREE-1289: Using legacy EjbEncInjector, because mappedName for enc "env/pl.com.stream.asen2.service2.impl.ComplexCounter/vatCounter", field "vatCounter" is null (container.environmentRefGroup.annotatedEjbReferences = [AnnotatedEJBReferenceMetaData{name=pl.com.stream.asen2.service2.impl.ComplexCounter/vatCounter,ejb-ref-type=null,link=null,ignore-dependecy=false,mapped/jndi-name=null,resolved-jndi-name=null,beanInterface=interface pl.com.stream.asen2.service1.commons.VatCounterLocal}])
      12:28:54,692 INFO [JBossASKernel] Created KernelDeployment for: Asen2Service2.jar
      12:28:54,692 INFO [JBossASKernel] installing bean: jboss.j2ee:jar=Asen2Service2.jar,name=ComplexCounter,service=EJB3
      12:28:54,692 INFO [JBossASKernel] with dependencies:
      12:28:54,692 INFO [JBossASKernel] and demands:
      12:28:54,693 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
      12:28:54,693 INFO [JBossASKernel] and supplies:
      12:28:54,693 INFO [JBossASKernel] jndi:ComplexCounter/local-pl.com.stream.asen2.service2.commons.ComplexCounterLocal
      12:28:54,693 INFO [JBossASKernel] jndi:ComplexCounter/local
      12:28:54,693 INFO [JBossASKernel] jndi:ComplexCounter/remote-pl.com.stream.asen2.service2.commons.ComplexCounterRemote
      12:28:54,693 INFO [JBossASKernel] Class:pl.com.stream.asen2.service2.commons.ComplexCounterRemote
      12:28:54,693 INFO [JBossASKernel] Class:pl.com.stream.asen2.service2.commons.ComplexCounterLocal
      12:28:54,693 INFO [JBossASKernel] jndi:ComplexCounter/remote
      12:28:54,693 INFO [JBossASKernel] Added bean(jboss.j2ee:jar=Asen2Service2.jar,name=ComplexCounter,service=EJB3) to KernelDeployment of: Asen2Service2.jar
      12:28:54,737 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=Asen2Service2.jar,name=ComplexCounter,service=EJB3
      12:28:54,738 INFO [SessionSpecContainer] Stopping jboss.j2ee:jar=Asen2Service2.jar,name=ComplexCounter,service=EJB3
      12:28:54,738 INFO [EJBContainer] STOPPED EJB: pl.com.stream.asen2.service2.impl.ComplexCounter ejbName: ComplexCounter
      12:28:54,738 ERROR [AbstractKernelController] Error installing to Start: name=jboss.j2ee:jar=Asen2Service2.jar,name=ComplexCounter,service=EJB3 state=Create
      java.lang.NullPointerException
       at org.jboss.ejb3.proxy.factory.ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(ProxyFactoryHelper.java:613)
       at org.jboss.ejb3.proxy.factory.ProxyFactoryHelper.getJndiName(ProxyFactoryHelper.java:419)
       at org.jboss.ejb3.Ejb3Deployment.getEjbJndiName(Ejb3Deployment.java:400)
       at org.jboss.ejb3.EJBContainer.getEjbJndiName(EJBContainer.java:1511)
       at org.jboss.injection.EjbEncInjector.inject(EjbEncInjector.java:80)
       at org.jboss.ejb3.EJBContainer.lockedStart(EJBContainer.java:894)
       at org.jboss.ejb3.session.SessionContainer.lockedStart(SessionContainer.java:164)
       at org.jboss.ejb3.session.SessionSpecContainer.lockedStart(SessionSpecContainer.java:606)
       at org.jboss.ejb3.stateless.StatelessContainer.lockedStart(StatelessContainer.java:247)
       at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:879)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59)
       at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:150)
       at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:241)
       at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:109)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:70)
       at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:221)
       at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)
       at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42)
       at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
       at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:774)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
       at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:121)
       at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:51)
       at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
       at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
       at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
       at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:545)
       at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:290)
       at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:221)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
       at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:280)
       at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:135)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:65)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:142)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:166)
       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
       at java.lang.Thread.run(Thread.java:595)
      12:28:54,781 WARN [HDScanner] Failed to process changes
      org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
      
      *** CONTEXTS IN ERROR: Name -> Error
      
      jboss.j2ee:jar=Asen2Service2.jar,name=ComplexCounter,service=EJB3 -> java.lang.NullPointerException
      
      
       at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:863)
       at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:665)
       at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:293)
       at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:221)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
       at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:280)
       at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:135)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:65)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:142)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:166)
       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
       at java.lang.Thread.run(Thread.java:595)
      


      This works in JBOSS 4.2.2.

      Can anyone tell me please how to inject my sessionbean?


        • 2. Re: How to inject sessionbean from sessionbean from another
          Kris Olszewski Newbie

          Thanx, this works fine.

          But ... :)

          1. This in not EJB3 compilant, i must use annotation org.jboss.ejb3.annotation.LocalBinding which is'n standard EJB annotation

          2. I' have another problem, when i'm redeploy first jar, (secon not), during redeploy server stops/starts VatCounter but do not stop/start ComplexCounter (which is depended) (Jboss 4.2.2 stops/starts both).
          And after that when im running ComplexCounter (from remote client) i get exception

          Exception in thread "AWT-EventQueue-0" java.lang.reflect.UndeclaredThrowableException
           at $Proxy2.getVatPoz(Unknown Source)
           at pl.com.stream.asen2.client.MainFrame$2.actionPerformed(MainFrame.java:65)
           at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
           at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
           at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
           at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
           at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
           at java.awt.Component.processMouseEvent(Component.java:6099)
           at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
           at java.awt.Component.processEvent(Component.java:5864)
           at java.awt.Container.processEvent(Container.java:2058)
           at java.awt.Component.dispatchEventImpl(Component.java:4466)
           at java.awt.Container.dispatchEventImpl(Container.java:2116)
           at java.awt.Component.dispatchEvent(Component.java:4296)
           at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
           at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
           at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
           at java.awt.Container.dispatchEventImpl(Container.java:2102)
           at java.awt.Window.dispatchEventImpl(Window.java:2454)
           at java.awt.Component.dispatchEvent(Component.java:4296)
           at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
           at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:284)
           at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
           at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
           at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
          Caused by: org.jboss.aop.DispatcherConnectException: EJB container is not completely started, or is stopped.
           at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:60)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
           at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
           at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:486)
           at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:56)
           at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)
           at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
           at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:908)
           at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
           at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
           at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)
           at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
           at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:206)
           at org.jboss.remoting.Client.invoke(Client.java:1708)
           at org.jboss.remoting.Client.invoke(Client.java:612)
           at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
           at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
           at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
           at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:76)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
           at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
           at $Proxy3.invoke(Unknown Source)
           at org.jboss.ejb3.proxy.handler.ProxyInvocationHandlerBase.invoke(ProxyInvocationHandlerBase.java:261)
           at org.jboss.ejb3.proxy.handler.session.SessionSpecProxyInvocationHandlerBase.invoke(SessionSpecProxyInvocationHandlerBase.java:101)
           at $Proxy2.getVatPoz(Unknown Source)
           at pl.com.stream.asen2.client.MainFrame$2.actionPerformed(MainFrame.java:65)
           at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
           at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
           at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
           at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
           at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
           at java.awt.Component.processMouseEvent(Component.java:6099)
           at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
           at java.awt.Component.processEvent(Component.java:5864)
           at java.awt.Container.processEvent(Container.java:2058)
           at java.awt.Component.dispatchEventImpl(Component.java:4466)
           at java.awt.Container.dispatchEventImpl(Container.java:2116)
           at java.awt.Component.dispatchEvent(Component.java:4296)
           at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
           at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
           at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
           at java.awt.Container.dispatchEventImpl(Container.java:2102)
           at java.awt.Window.dispatchEventImpl(Window.java:2454)
           at java.awt.Component.dispatchEvent(Component.java:4296)
           at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
           at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:284)
           at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
           at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
           at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
           at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
           at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
           at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
           at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:76)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
           at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
           at $Proxy3.invoke(Unknown Source)
           at org.jboss.ejb3.proxy.handler.ProxyInvocationHandlerBase.invoke(ProxyInvocationHandlerBase.java:261)
           at org.jboss.ejb3.proxy.handler.session.SessionSpecProxyInvocationHandlerBase.invoke(SessionSpecProxyInvocationHandlerBase.java:101)
           ... 27 more
          
          


          • 3. Re: How to inject sessionbean from sessionbean from another
            jaikiran pai Master

             

            1. This in not EJB3 compilant, i must use annotation org.jboss.ejb3.annotation.LocalBinding which is'n standard EJB annotation


            Instead you can configure the jndi-name and local-jndi-name for the bean in a jboss.xml file. In EJB3.0 the spec does not talk about a standard default global jndi name. However, EJB3.1 proposes a standard default global jndi name for the beans.


            • 4. Re: How to inject sessionbean from sessionbean from another
              jaikiran pai Master

               

              "kolszew73" wrote:

              2. I' have another problem, when i'm redeploy first jar, (secon not), during redeploy server stops/starts VatCounter but do not stop/start ComplexCounter (which is depended) (Jboss 4.2.2 stops/starts both).

              ComplexCounter is dependent on VatCounter. So stopping/undeploying VatCounter should have also stopped/undeployed ComplexCounter. If that's not happening then maybe you have discovered an issue. Could you please file a JIRA here https://jira.jboss.org/jira/browse/EJBTHREE with the details and if possible a sample application which shows this issue?



              • 5. Re: How to inject sessionbean from sessionbean from another
                Andrew Rubinger Master

                 

                "kolszew73" wrote:
                1. This in not EJB3 compilant, i must use annotation org.jboss.ejb3.annotation.LocalBinding which is'n standard EJB annotation


                Strong words from someone trying to bypass spec scoping by injecting across unrelated JARs/EARs. ;)

                True story though. Looking forward we'll be moving the injection framework to the new pluggable @EJB reference resolvers, which will optionally support injection across any EJB3 DeploymentUnits registered w/ the MainDeployer.

                These were defined: https://jira.jboss.org/jira/browse/EJBTHREE-1616

                S,
                ALR

                • 6. Re: How to inject sessionbean from sessionbean from another
                  Kris Olszewski Newbie

                  Ok i know, but ... it works fine in JBOSS 4.2.2 !

                  • 7. Re: How to inject sessionbean from sessionbean from another
                    Andrew Rubinger Master

                     

                    "kolszew73" wrote:
                    Ok i know, but ... it works fine in JBOSS 4.2.2 !


                    I'm sympathetic to this in practice. So:

                    https://jira.jboss.org/jira/browse/EJBTHREE-1689

                    S,
                    ALR

                    • 8. Re: How to inject sessionbean from sessionbean from another
                      Andre Ehrlich Newbie

                      Hey there!

                      I have a similar question, but the @RemoteBinding Solution doesn't work.

                      My JBoss AS 5.0.0.GA runs in "all" mode, because I need clustering capabilities. I have a usual EJB_JAR in folder "deploy" and a SAR in "deploy-hasingleton". The SAR contains an MBean which uses a SLSB defined in the EJB-JAR:

                      public class Master implements MasterMBean {
                      
                      @Resource(mappedName = Calculator.JNDI_NAME)
                      private Calculator additionBean;
                      
                      // ... MBean stuff


                      The Bean is just a simple Calculator, which adds the given numbers:
                      @Clustered
                      @Stateless(mappedName = Calculator.JNDI_NAME)
                      @Remote(Calculator.class)
                      public class CalculatorBean implements Calculator {
                      
                       public long add(int... summands) {
                       long result = 0;
                      
                       for (int i : summands) {
                       result += (long) i;
                       }
                       return result;
                       }
                      }


                      When starting the server, the MBean can't use the Calculator, behause it was not injected. But the injection works pretty fine for a SLSB defined in a second EJB-JAR.

                      Is this a problem with the two different deploy folders? Or am I doing something wrong?

                      Thanks,
                      Andre

                      • 9. Re: How to inject sessionbean from sessionbean from another
                        jaikiran pai Master

                        Please post the console logs when the server is being started and your application being deployed.

                        • 10. Re: How to inject sessionbean from sessionbean from another
                          Andre Ehrlich Newbie

                          Sure. I hope, this is everything you need:

                          11:32:01,640 INFO [ServerPeer] JBoss Messaging 1.4.1.GA server [0] started
                          11:32:01,812 INFO [STDOUT]
                          -------------------------------------------------------
                          GMS: address is 192.168.22.42:2527
                          -------------------------------------------------------
                          11:32:03,828 INFO [GroupMember] org.jboss.messaging.core.impl.postoffice.GroupMember$ControlMembershipListener@4d98da got new view [192.168.22
                          11:32:03,828 INFO [GroupMember] I am (192.168.22.42:2527)
                          11:32:03,828 INFO [GroupMember] New Members : 1 ([192.168.22.42:2527])
                          11:32:03,828 INFO [GroupMember] All Members : 1 ([192.168.22.42:2527])
                          11:32:03,828 INFO [STDOUT]
                          -------------------------------------------------------
                          GMS: address is 192.168.22.42:7900
                          -------------------------------------------------------
                          11:32:08,890 INFO [QueueService] Queue[/queue/ExpiryQueue] started, fullSize=200000, pageSize=2000, downCacheSize=2000
                          11:32:08,968 INFO [ConnectionFactory] Connector bisocket://fup-dd-ap-12:4457 has leasing enabled, lease period 10000 milliseconds
                          11:32:08,968 INFO [ConnectionFactory] org.jboss.jms.server.connectionfactory.ConnectionFactory@13c7b26 started
                          11:32:09,000 INFO [ConnectionFactory] Connector bisocket://fup-dd-ap-12:4457 has leasing enabled, lease period 10000 milliseconds
                          11:32:09,000 INFO [ConnectionFactory] org.jboss.jms.server.connectionfactory.ConnectionFactory@10eb73 started
                          11:32:09,015 INFO [QueueService] Queue[/queue/DLQ] started, fullSize=200000, pageSize=2000, downCacheSize=2000
                          11:32:09,312 WARN [JBossASSecurityMetadataStore] WARNING! POTENTIAL SECURITY RISK. It has been detected that the MessageSucker component which
                          11:32:09,718 INFO [ConnectionFactory] Connector bisocket://fup-dd-ap-12:4457 has leasing enabled, lease period 10000 milliseconds
                          11:32:09,718 INFO [ConnectionFactory] org.jboss.jms.server.connectionfactory.ConnectionFactory@1219df4 started
                          11:32:09,718 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI na
                          11:32:09,765 INFO [TomcatDeployment] deploy, ctxPath=/, vfsUrl=ROOT.war
                          11:32:09,812 INFO [TomcatDeployment] deploy, ctxPath=/jmx-console, vfsUrl=jmx-console.war
                          11:32:10,140 INFO [JBossASKernel] Created KernelDeployment for: SubEJB.jar
                          11:32:10,156 INFO [JBossASKernel] installing bean: jboss.j2ee:jar=SubEJB.jar,name=CalculatorBean,service=EJB3
                          11:32:10,156 INFO [JBossASKernel] with dependencies:
                          11:32:10,156 INFO [JBossASKernel] and demands:
                          11:32:10,156 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
                          11:32:10,156 INFO [JBossASKernel] and supplies:
                          11:32:10,156 INFO [JBossASKernel] jndi:AECalculator
                          11:32:10,156 INFO [JBossASKernel] jndi:CalculatorBean/remote-ae.Calculator
                          11:32:10,156 INFO [JBossASKernel] Class:ae.Calculator
                          11:32:10,156 INFO [JBossASKernel] Added bean(jboss.j2ee:jar=SubEJB.jar,name=CalculatorBean,service=EJB3) to KernelDeployment of: SubEJB.jar
                          11:32:10,265 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=SubEJB.jar,name=CalculatorBean,service=EJB3
                          11:32:10,265 INFO [EJBContainer] STARTED EJB: ae.CalculatorBean ejbName: CalculatorBean
                          11:32:10,312 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

                          AECalculator - EJB3.x Default Remote Business Interface
                          CalculatorBean/remote-ae.Calculator - EJB3.x Remote Business Interface

                          11:32:10,343 ERROR [Master] ### unable to inject CalculatorBean!!!
                          11:32:10,390 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
                          11:32:10,406 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-0.0.0.0-8009
                          11:32:10,406 INFO [ServerImpl] JBoss (Microcontainer) [5.0.0.GA (build: SVNTag=JBoss_5_0_0_GA date=200812041714)] Started in 45s:63ms


                          Thanks for your help!
                          Andre

                          • 11. Re: How to inject sessionbean from sessionbean from another
                            jaikiran pai Master

                             

                            public class Master implements MasterMBean {


                            What is this class (into which you are injection the EJB)? Are you using the @Service annotation? Or are you configuring the service through xml? Can you post the configurations?

                            • 12. Re: How to inject sessionbean from sessionbean from another
                              Andre Ehrlich Newbie

                              Master.java

                              package ae;
                              
                              import javax.annotation.Resource;
                              
                              import org.apache.log4j.Logger;
                              
                              import ae.Calculator;
                              
                              public class Master implements MasterMBean {
                               private static final Logger log = Logger.getLogger(Master.class);
                              
                               @Resource(mappedName = Calculator.JNDI_NAME)
                               private Calculator additionBean;
                              
                               public void start() throws Exception {
                               if (additionBean == null) {
                               log.error("### unable to inject CalculatorBean!!!");
                               return;
                               }
                              
                               long result = additionBean.add(new int[] { 1, 2, 3 });
                               log.info(result);
                              
                               // TODO use a quartz job to run a calculation every 5 seconds!
                               }
                              
                               public void stop() {}
                              }
                              


                              master-mbean-service.xml:
                              <?xml version="1.0" encoding="UTF-8"?>
                              
                              <server>
                               <mbean code="ae.Master" name="ae:service=Master">
                               <depends>
                               jboss.j2ee:jar=SubEJB.jar,name=CalculatorBean,service=EJB3
                               </depends>
                               </mbean>
                              </server>
                              


                              Calculator.java:
                              package ae;
                              
                              public interface Calculator {
                               public static final String JNDI_NAME = "AECalculator";
                               public long add(int... summands);
                              }
                              


                              CalculatorBean.java:
                              package ae;
                              
                              import javax.ejb.Remote;
                              import javax.ejb.Stateless;
                              
                              import org.apache.log4j.Logger;
                              import org.jboss.ejb3.annotation.Clustered;
                              
                              @Clustered
                              @Stateless(mappedName = Calculator.JNDI_NAME)
                              @Remote(Calculator.class)
                              public class CalculatorBean implements Calculator {
                               private static final Logger log = Logger.getLogger(CalculatorBean.class);
                              
                               public long add(int... summands) {
                               long result = 0;
                               for (int i : summands) {
                               result += (long) i;
                               }
                               log.info(result);
                               return result;
                               }
                              }
                              


                              • 13. Re: How to inject sessionbean from sessionbean from another
                                Andre Ehrlich Newbie

                                Jaikiran, I just tried the @Service notation:

                                package ae;
                                
                                import javax.annotation.Resource;
                                import javax.ejb.TransactionAttribute;
                                import javax.ejb.TransactionAttributeType;
                                
                                import org.apache.log4j.Logger;
                                import org.jboss.ejb3.annotation.Depends;
                                import org.jboss.ejb3.annotation.Management;
                                import org.jboss.ejb3.annotation.Service;
                                
                                @Service
                                @Management(MasterMBean.class)
                                @Depends( { "jboss.j2ee:jar=SubEJB.jar,name=CalculatorBean,service=EJB3" })
                                public class Master implements MasterMBean {
                                
                                 private static final Logger log = Logger.getLogger(Master.class);
                                
                                 @EJB(mappedName = Calculator.JNDI_NAME)
                                 private Calculator additionBean;
                                
                                 @TransactionAttribute(TransactionAttributeType.NEVER)
                                 public void start() throws Exception {
                                 log.info("### starting");
                                
                                 if (additionBean == null) {
                                 log.error("### unable to inject CalculatorBean!!!");
                                 return;
                                 }
                                
                                 long result = additionBean.add(new int[] { 1, 2, 3 });
                                 log.info(result);
                                
                                 // TODO use a quartz job to run a calculation every 5 seconds!
                                 }
                                
                                 public void stop() {
                                 log.info("### stopping");
                                 }
                                }
                                


                                After removing the master-mbean-jboss.xml and deploying the SAR into server/all/deploy-hasingleton, the Injection worked pretty fine! But the old approach still does not work. Can you tell me why?

                                Another thing: as you can see, I had to annotate the start() method, because I got an Exception:

                                14:54:06,031 INFO [ConnectionFactory] org.jboss.jms.server.connectionfactory.ConnectionFactory@1e287e5 started
                                14:54:06,031 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA'
                                14:54:06,093 INFO [TomcatDeployment] deploy, ctxPath=/, vfsUrl=ROOT.war
                                14:54:06,156 INFO [TomcatDeployment] deploy, ctxPath=/jmx-console, vfsUrl=jmx-console.war
                                14:54:06,265 INFO [JBossASKernel] Created KernelDeployment for: SubEJB.jar
                                14:54:06,265 INFO [JBossASKernel] installing bean: jboss.j2ee:jar=SubEJB.jar,name=CalculatorBean,service=EJB3
                                14:54:06,265 INFO [JBossASKernel] with dependencies:
                                14:54:06,265 INFO [JBossASKernel] and demands:
                                14:54:06,265 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
                                14:54:06,265 INFO [JBossASKernel] and supplies:
                                14:54:06,265 INFO [JBossASKernel] jndi:AECalculator
                                14:54:06,265 INFO [JBossASKernel] jndi:CalculatorBean/remote-ae.Calculator
                                14:54:06,265 INFO [JBossASKernel] Class:ae.Calculator
                                14:54:06,265 INFO [JBossASKernel] Added bean(jboss.j2ee:jar=SubEJB.jar,name=CalculatorBean,service=EJB3) to KernelDeployment of: SubEJB.jar
                                14:54:06,375 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=SubEJB.jar,name=CalculatorBean,service=EJB3
                                14:54:06,390 INFO [EJBContainer] STARTED EJB: ae.CalculatorBean ejbName: CalculatorBean
                                14:54:06,437 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

                                AECalculator - EJB3.x Default Remote Business Interface
                                CalculatorBean/remote-ae.Calculator - EJB3.x Remote Business Interface

                                14:54:06,593 INFO [EJBContainer] STARTED EJB: ae.Master ejbName: Master
                                14:54:06,609 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:


                                14:54:06,625 INFO [JBossASKernel] installing bean: jboss.j2ee:jar=master.sar,name=Master,service=EJB3,type=ManagementInterface
                                14:54:06,625 INFO [JBossASKernel] with dependencies:
                                14:54:06,625 INFO [JBossASKernel] and demands:
                                14:54:06,625 INFO [JBossASKernel] jndi:AECalculator
                                14:54:06,625 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
                                14:54:06,625 INFO [JBossASKernel] jboss.j2ee:jar=SubEJB.jar,name=CalculatorBean,service=EJB3
                                14:54:06,625 INFO [JBossASKernel] and supplies:
                                14:54:06,625 INFO [JBossASKernel] jndi:Master/remote
                                14:54:06,625 INFO [JBossASKernel] Class:ae.MasterMBean
                                14:54:06,625 INFO [JBossASKernel] Installing bean(jboss.j2ee:jar=master.sar,name=Master,service=EJB3,type=ManagementInterface) into kernel
                                14:54:06,640 INFO [Master] ### starting
                                14:54:06,687 ERROR [ServiceContainer] Encountered an error in start of Master
                                java.lang.RuntimeException: Problem registering @Management interface for @Service class ae.Master
                                at org.jboss.ejb3.service.ServiceContainer.registerManagementInterface(ServiceContainer.java:727)
                                [...]
                                at java.lang.Thread.run(Thread.java:595)
                                Caused by: java.lang.RuntimeException: javax.management.MBeanException
                                at org.jboss.ejb3.deployers.JBossASKernel.installMBean(JBossASKernel.java:181)
                                at org.jboss.ejb3.service.ServiceContainer.registerManagementInterface(ServiceContainer.java:699)
                                ... 50 more
                                Caused by: javax.management.MBeanException
                                at org.jboss.ejb3.service.ServiceMBeanDelegate.invoke(ServiceMBeanDelegate.java:219)
                                at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
                                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
                                at org.jboss.ejb3.deployers.JBossASKernel.invokeOptionalMethod(JBossASKernel.java:287)
                                at org.jboss.ejb3.deployers.JBossASKernel.installMBean(JBossASKernel.java:177)
                                ... 51 more
                                Caused by: javax.ejb.EJBException: java.lang.RuntimeException: cannot import a transaction context when a transaction is already associated with the thread
                                at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:77)
                                at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
                                at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
                                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                                at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
                                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
                                at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)

                                Why is that, actually? I don't have any problems when looking up the bean manually

                                Greetings,
                                Andre