2 Replies Latest reply on Jul 20, 2006 2:04 PM by Rene Sprotte

    env-entry injection in a @Service EJB

    Rene Sprotte Newbie

      Hi,

      I would ask how I can do an env-entry injection into an jboss @Service EJB? There are many examples how this can be done with session beans and also message driven bean. But I could not find anything how to inject a primary type resource into a @Service EJB.

      I have the following test service:

      @Service
      public class MyTestServiceBean implements MyTestService {
      
       @Resource(name = "maxValue") public int maxValue = 10;
      
       public MyTestServiceBean() {
       System.out.println("MAX_VALUE: " + maxValue);
       }
      
       public void test() {
       // ...
       }
      
      }
      


      In ejb-jar.xml I tried something like this (which I didn't really expected to work)
      <ejb-jar>
       <enterprise-beans>
       <env-entry>
       <env-entry-name>maxValue</env-entry-name>
       <env-entry-type>java.lang.Integer</env-entry-type>
       <env-entry-value>1000</env-entry-value>
       </env-entry>
       </enterprise-beans>
      </ejb-jar>
      


      I also tried many variations with <injection-target> and setting this stuff in jboss.xml. But nothing worked so far.

      Thanks in advance,

      René


        • 1. Re: env-entry injection in a @Service EJB
          Carlo de Wolf Master

          Please try the following:

          <?xml version="1.0"?>
          
          <ejb-jar
           xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
           http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
           version="3.0">
           <display-name>EnvEntry Tests</display-name>
           <enterprise-beans>
           <session>
           <ejb-name>TestEnvEntry</ejb-name>
           <env-entry>
           <env-entry-name>maxExceptions</env-entry-name>
           <env-entry-type>java.lang.Integer</env-entry-type>
           <env-entry-value>15</env-entry-value>
           </env-entry>
           <env-entry>
           <env-entry-name>minExceptions</env-entry-name>
           <env-entry-type>java.lang.Integer</env-entry-type>
           <env-entry-value>5</env-entry-value>
           <injection-target>
           <injection-target-class>org.jboss.ejb3.test.enventry.TestEnvEntryBean</injection-target-class>
           <injection-target-name>minExceptions</injection-target-name>
           </injection-target>
           </env-entry>
           <env-entry>
           <env-entry-name>org.jboss.ejb3.test.enventry.TestEnvEntryBean/numExceptions</env-entry-name>
           <env-entry-type>java.lang.Integer</env-entry-type>
           <env-entry-value>10</env-entry-value>
           </env-entry>
           </session>
           </enterprise-beans>
          </ejb-jar>
          

          With the first one you need:
          @Resource(name="maxExceptions") private int maxExceptions;


          • 2. Re: env-entry injection in a @Service EJB
            Rene Sprotte Newbie

            Hi,

            when I try

            <?xml version="1.0"?>
            
            <ejb-jar
             xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
             http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
             version="3.0">
             <display-name>EnvEntry Tests</display-name>
             <enterprise-beans>
             <session>
             <ejb-name>MyTestServiceBean</ejb-name>
             <env-entry>
             <env-entry-name>maxExceptions</env-entry-name>
             <env-entry-type>java.lang.Integer</env-entry-type>
             <env-entry-value>15</env-entry-value>
             </env-entry>
             </session>
             </enterprise-beans>
            </ejb-jar>
            


            together with:

            @Service
            public class MyTestServiceBean implements MyTestService {
            
             @Resource(name="maxExceptions") private int maxExceptions;
            
             public MyTestServiceBean() {
             System.out.println("MAX_EXCPT: " + maxExceptions);
             }
            }
            


            I'll get the following exception:

            19:48:30,715 WARN [ServiceController] Problem creating service jboss.j2ee:service=EJB3,module=openstam-core-1.0dev.jar
            java.lang.ClassCastException: org.jboss.ejb3.dd.SessionEnterpriseBean
             at org.jboss.ejb3.Ejb3DescriptorHandler.getServiceContainer(Ejb3DescriptorHandler.java:297)
             at org.jboss.ejb3.Ejb3AnnotationHandler.getContainers(Ejb3AnnotationHandler.java:153)
             at org.jboss.ejb3.Ejb3Deployment.deployElement(Ejb3Deployment.java:567)
             at org.jboss.ejb3.Ejb3Deployment.deployElement(Ejb3Deployment.java:555)
             at org.jboss.ejb3.Ejb3Deployment.deployUrl(Ejb3Deployment.java:536)
             at org.jboss.ejb3.Ejb3Deployment.deploy(Ejb3Deployment.java:508)
             at org.jboss.ejb3.Ejb3Deployment.create(Ejb3Deployment.java:463)
             at org.jboss.ejb3.Ejb3Module.createService(Ejb3Module.java:125)
             at org.jboss.system.ServiceMBeanSupport.jbossInternalCreate(ServiceMBeanSupport.java:260)
             at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:243)
             at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             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.create(Unknown Source)
             at org.jboss.system.ServiceController.create(ServiceController.java:330)
             at org.jboss.system.ServiceController.create(ServiceController.java:273)
             at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             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 $Proxy34.create(Unknown Source)
             at org.jboss.ejb3.EJB3Deployer.create(EJB3Deployer.java:429)
             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.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.ws.integration.jboss.DeployerInterceptor.create(DeployerInterceptor.java:74)
             at org.jboss.ws.integration.jboss.DeployerInterceptorEJB.create(DeployerInterceptorEJB.java:44)
             at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.create(SubDeployerInterceptorSupport.java:180)
             at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:91)
             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 $Proxy35.create(Unknown Source)
             at org.jboss.deployment.MainDeployer.create(MainDeployer.java:953)
             at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:807)
             at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:771)
             at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             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 $Proxy6.deploy(Unknown Source)
             at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
             at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
             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)
            


            I'm running jboss 4.0.4GA with EJB3 RC8. I didn't expected this to work, because the ejb-jar.xml "speaks" about a session bean and I have a @Service Bean, which is a jboss specific thing.

            Is this expected to work? Is this a bug? Or, is this simply not possible?

            Thanks, René