6 Replies Latest reply on May 7, 2009 9:24 AM by larry.vladechko.gmail.com

    injection @In Stateless bean - @In attribute requires non-null value problem

    larry.vladechko.gmail.com
      Trying to run ear app runs on Glassfish got an error:

      @In attribute requires non-null value: test.foo


      My Seam bean (inside war module of ear):

      @Name("test")
      public class TestBean {
         
          @In
          private SecurityEjbLocal foo;

          public String getFoo(){
              // foo = lookupSecurityEjb();  - it's ok!
              return foo.getFoo();
          }


          private SecurityEjbLocal lookupSecurityEjb() {
              try {
                  Context c = new InitialContext();
                  return (SecurityEjbLocal) c.lookup("java:comp/env/SecurityEjb");
              } catch (NamingException ne) {
                  Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
                  throw new RuntimeException(ne);
              }
          }

      }

      My EJB (inside jar of ear)

      @Stateless
      @Name("foo")
      public class SecurityEjb implements SecurityEjbLocal {
      public String getFoo(){
         return "FOO";
      }
      }

      @Local
      public interface SecurityEjbLocal {
        String getFoo();
      }


      Seam Log:
      ...
      INFO Component:237 - Component: foo, scope: STATELESS, type: STATELESS_SESSION_BEAN, class: org.mycubic.ejb.security.SecurityEjb, JNDI: java:comp/env/SecurityEjb
      ...
        • 1. Re: injection @In Stateless bean - @In attribute requires non-null value problem
          niox.nikospara.yahoo.com

          Hello,


          I am not sure if it applies to stateless SBs, but you may try @In(create=true), if foo is required, or @In(required=false) if not. An alternative is to specify @AutoCreate at class level for the SecurityEjb. See ch4, section Bijection in the manual.

          • 2. Re: injection @In Stateless bean - @In attribute requires non-null value problem
            larry.vladechko.gmail.com
            If I try using @In(required=false, create=true), I get the  error:

            org.jboss.seam.InstantiationException: Could not instantiate Seam component: foo

            root cause is:
            java.lang.ClassNotFoundException: SecurityEjbLocal

            I have read this topic

            http://www.seamframework.org/Community/UsingEJBToInjectAnEJBIntoAComponent#comment29234

            there is described the similar problem.

            but here is ref declaration
                   <ejb-local-ref>
                        <ejb-ref-name>SecurityEjb</ejb-ref-name>
                        <ejb-ref-type>Session</ejb-ref-type>
                        <local>org.mycubic.ejb.security.SecurityEjbLocal</local>
                    </ejb-local-ref>
            in my web.xml

            and
              jndi pattern is defined as

            java:comp/env/#{ejbName}   in components.xml

            jndi look up works well



            • 3. Re: injection @In Stateless bean - @In attribute requires non-null value problem
              niox.nikospara.yahoo.com

              Hi again,


              I believe that your problem is quite different than that of http://www.seamframework.org/Community/UsingEJBToInjectAnEJBIntoAComponent. Yours is a ClassNotFoundException.


              And just to make sure: Is the message displayed


              java.lang.ClassNotFoundException: SecurityEjbLocal



              OR something like:


              java.lang.ClassNotFoundException: org/mycubic/ejb/security/SecurityEjbLocal



              I.e. is the full package/path to your class displayed? If NOT, it means that you have given plain class name instead of fully classified name somewhere (moset probably deployment descriptors).


              If that is OK, can you give us a simplified directory structure of your exploded application EAR, showing the location of SecurityEjbLocal.class, TestBean.class and SecurityEjb.class? (Please use formatting)

              • 4. Re: injection @In Stateless bean - @In attribute requires non-null value problem
                larry.vladechko.gmail.com

                Hi,


                Error message displays with full path ie
                java.lang.ClassNotFoundException: org/mycubic/ejb/security/SecurityEjbLocal


                I have created another one simple project and get the same error (ClassNotFoundException)


                my ejb:


                
                @Stateless
                @Name("ejbbean")
                public class EjbBean implements EjbBeanLocal {
                    
                    public String getStr(){
                        return "It works!";
                    }
                 
                }
                
                @Local
                public interface EjbBeanLocal {
                
                    public java.lang.String getStr();
                    
                }
                
                



                war includes one jsf page:


                
                <h:outputText value="#{ejbbean.str}" />
                
                



                and one seam bean


                
                @Name("warbean")
                public class WarBean {
                
                    
                  //  @In(value="ejbbean",required=false,create=true) <-- this injection throws exception 
                    private EjbBeanLocal my;
                
                    public String getStr(){
                        my = lookupEjbBean();  // <-- this works fine
                        return my.getStr();
                    }
                
                    private EjbBeanLocal lookupEjbBean() {
                        try {
                            Context c = new InitialContext();
                            return (EjbBeanLocal) c.lookup("java:comp/env/EjbBean");
                        } catch (NamingException ne) {
                            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
                            throw new RuntimeException(ne);
                        }
                    }
                }
                
                



                both jsf page and seam bean (warbean) throws an exception when calls to ejbbean


                org.jboss.seam.InstantiationException: Could not instantiate Seam component: ejbbean


                root cause is
                java.lang.NoClassDefFoundError: ejb/EjbBeanLocal


                here is my ear structure:


                
                /META-INF
                /J2EE.dpf
                /jboss-el.jar
                /jboss-seam.jar
                /TrySeam-ejb.jar
                /TrySeam-war.war
                
                



                TrySeam-war.war:


                
                /META-INF/
                /WEB-INF/
                /WEB-INF/classes/
                /WEB-INF/classes/seam.properties
                /WEB-INF/classes/WarBean.class
                
                /WEB-INF/components.xml
                /WEB-INF/faces-config.xml
                /WEB-INF/sun-web.xml
                /WEB-INF/web.xml
                
                /forward.jsp
                /index.jsp
                
                
                



                TrySeam-ejb.jar:


                /ejb/
                /ejb/EjbBean.class
                /ejb/EjbBeanLocal.class
                /META-INF/
                /META-INF/ejb-jar.xml
                /META-INF/MANIFEST.MF
                /META-INF/seam.properties
                /seam.properties
                
                
                



                • 5. Re: injection @In Stateless bean - @In attribute requires non-null value problem
                  niox.nikospara.yahoo.com

                  Things look normal to me, so -unfortunately- I cannot provide any further assistance.


                  Some thoughts:


                  Did you do things as described in the manual? Did you try to deploy the samples in Glassfish?


                  Could it be a Glassfish classloader-related error? (I have no experience with Glassfish)


                  EjbBean and EjbBeanLocal are side-by-side so they should be loaded by the same classloader. Are you sure that there is no copy of either class in the wrong directory (eg WEB-IN/classes)?


                  WarBean references EjbBeanLocal and the classloader doesnt complain. WarBean is loaded by the war classloader. What is going on here?


                  Can you call Class.forName("ejb.EjbBeanLocal") from an EJB and a JSP (or servlet) to see (a) if the class gets loaded and (b) which classloader loaded it?


                  Could the following be related? http://www.seamframework.org/Community/PleaseHelpCouldNotInstantiateSeamComponent

                  • 6. Re: injection @In Stateless bean - @In attribute requires non-null value problem
                    larry.vladechko.gmail.com

                    Nikos thanks for y help!
                    I have fixed this!
                    there was an another copy of jboss-seam.jar in my Glassfish domain lib directory.
                    When I have removed it from domain libs project - the project start work well.