3 Replies Latest reply on Feb 3, 2007 11:31 AM by berkum

    Can I use @EJB-style dependency injection in a Servlet withi

    smokingapipe

      I have been trying to get that to work, and I get nothing. I have a feeling that the dependency injector code needs to run on the Servlet object after it has been instantiated, and I have a feeling that Tomcat is not doing that. I saw on this page:

      http://www.netbeans.org/kb/articles/javaee5-hello-world.html

      Note: GlassFish already supports Servlet 2.5 and JSF 1.2 with Java EE 5 annotations for dependency injection in web tier. If you want to use JBoss you can test a standalone EJB module and use either J2SE client or use JNDI lookup to call the EJB.


      which suggests that I need to use JNDI within JBoss / Tomcat.

      Am I reading this correctly? I have tried everything to get @EJB working within my app and it just isn't working. Either I'm doing something wrong or it doesn't work.

      Thanks


        • 1. Re: Can I use @EJB-style dependency injection in a Servlet w
          starksm64

          The servlet side injection is still in progress.

          • 2. Re: Can I use @EJB-style dependency injection in a Servlet w
            smokingapipe

            Thanks Scott. That explains why that method wasn't working in my code!

            Then I have a couple more questions:

            What's the best way to manage my InitialContext? Should I maybe create it in the constructor of my JSF backing bean?

            Second question: I notice that you are with RedHat and the JBoss project. I am aware that RH has been putting a lot of support behind efforts to create a full open source Java stack, including gcj and Gnu Classpath. Are we at some point going to have a full open-source Java stack (gcj) that can compile Tomcat and JBoss so we can use the whole thing without Sun's Java? I hope so! And even if we don't, I think gcj is great. I have done some small testing of it and am very impressed.

            Thanks

            • 3. Re: Can I use @EJB-style dependency injection in a Servlet w
              berkum

              Finally found this post. I am currently using Jboss 4.0.5 GA and I can't inject ejbs from servlets. Is this something you plan in the near future or as it been fixed and I am simply not using it correctly ?

              Thank you.