1 Reply Latest reply on Jul 11, 2010 4:54 AM by jaikiran pai

    Dependency Injection in EJB3

    Swamy Nathan Newbie

      Hi,

       

      1. ) Can I inject a simple POJO Java bean/object using @javax.annotation.Resource into a EJB- Can we do this inside an EJB.

                @Resource

                private SimpleNotEjbType type;

       

      2. ) Can I inject a DataSource using @javax.annotation.Resource into a non-ejb POJO being invoked by my EJB?

           public class SimpleNotEjbType

           {

                @Resource(mappedName="MyDS")

                private DataSource ds;

           }

       

      Thanks.

      S

        • 1. Re: Dependency Injection in EJB3
          jaikiran pai Master

          Swamy Nathan wrote:

           

           

           

          1. ) Can I inject a simple POJO Java bean/object using @javax.annotation.Resource into a EJB- Can we do this inside an EJB.

                    @Resource

                    private SimpleNotEjbType type;

           


          Is the SimpleNotEjbType available in JNDI? If yes, then you can use the mappedName attribute of the @Resource to point to the jndi name of that resource and have it injected:

           

          @Resource (mappedName="jndiname")
          private SimpleNotEjbType type;
          

           

           

          Swamy Nathan wrote:

           

          2. ) Can I inject a DataSource using @javax.annotation.Resource into a non-ejb POJO being invoked by my EJB?

               public class SimpleNotEjbType

               {

                    @Resource(mappedName="MyDS")

                    private DataSource ds;

               }

           

          No, the EJB container will not inject the resources into that POJO class.