4 Replies Latest reply on Jan 8, 2010 2:23 AM by johaneltes

    Is @Resource + @Produces ok?

      The following code causes infinite recursion when deployed to glassfish embeddable Java EE 6 EJB container:




      package foo.bar;
      
      import javax.annotation.Resource;
      import javax.annotation.sql.DataSourceDefinition;
      import javax.enterprise.inject.Produces;
      import javax.inject.Inject;
      import javax.sql.DataSource;
      
      @DataSourceDefinition(name = "java:app/env/DerbyDb",
                 minPoolSize = 0,
                 initialPoolSize = 0,
                 className = "org.apache.derby.jdbc.EmbeddedDataSource",
                 user = "test",
                 password = "test",
                 databaseName = "derbyTestDb",
                 properties = {"connectionAttributes=;create=true"}
              )
      public class ResourceProducers {
           @Produces @Resource(name="java:app/env/DerbyDb") DataSource dataSource;
           @Inject DataSource dataSourceInjectionPoint;
           
      }



        • 1. Re: Is @Resource + @Produces ok?

          Some more testing...


          It does not seem to relate to combining @Produces with @Resource. I get the stack overflow even with this:




          package foo.bar;
          
          import javax.annotation.Resource;
          import javax.annotation.sql.DataSourceDefinition;
          import javax.sql.DataSource;
          
          @DataSourceDefinition(name = "java:app/DerbyDb",
                     minPoolSize = 0,
                     initialPoolSize = 0,
                     className = "org.apache.derby.jdbc.EmbeddedDataSource",
                     user = "test",
                     password = "test",
                     databaseName = "derbyTestDb",
                     properties = {"connectionAttributes=;create=true"}
                  )
          public class ResourceProducers {
               @Resource(mappedName="java:app/DerbyDb") DataSource dataSource;
               
          }



          • 2. Re: Is @Resource + @Produces ok?

            Sorry - should have been...




            package foo.bar;
            
            import javax.annotation.Resource;
            import javax.annotation.sql.DataSourceDefinition;
            import javax.sql.DataSource;
            
            @DataSourceDefinition(name = "java:app/DerbyDb",
                       minPoolSize = 0,
                       initialPoolSize = 0,
                       className = "org.apache.derby.jdbc.EmbeddedDataSource",
                       user = "test",
                       password = "test",
                       databaseName = "derbyTestDb",
                       properties = {"connectionAttributes=;create=true"}
                    )
            public class ResourceProducers {
                 @Resource(name="java:app/DerbyDb") DataSource dataSource;
                 
            }



            • 3. Re: Is @Resource + @Produces ok?
              gavin.king

              Well, there's no actual CDI functionality used there. Just javax.annotation stuff (@Resource and @DataSourceDefinition).

              • 4. Re: Is @Resource + @Produces ok?

                Yep, that's where it ended up. Sorry for make noise in the wrong context. The defect report went to Glassfish though.