1 Reply Latest reply on Jun 13, 2011 6:48 AM by yang xin

    Something strange with @Producer

    yang xin Newbie
      My project need a JDBCDAO util.
      so I write below:
      the qualifier:
      @Qualifier
      @Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
      @Retention(RetentionPolicy.RUNTIME)
      public @interface JDBCDao {
          @Nonbinding public String value() default "";
      }

      the Producer :
      public class DaoProductor {
          @Produces @JDBCDao
          public BaseJdbcDao getJdbcDao(InjectionPoint ip){
              String JNDIName = ip.getAnnotated().getAnnotation(JDBCDao.class).value();
              if( JNDIName.compareTo("")==0)
                  return null;
              try{
                  DataSource dataSource = (javax.sql.DataSource) new javax.naming.InitialContext().lookup(JNDIName);
                  if( dataSource == null )
                      return null;
                  return new BaseJdbcDao(dataSource);
              }catch(Exception ex){
                  ex.printStackTrace();
                  return null;
              }
          }
      }
      and at the same project the test Code:

      @Inject @JDBCDao("jdbc/pool") BaseJdbcDao dao;

      works well


      SO I package the Qualifier,Produces,and daoutil into a jar file,
      my real project import the jar
      when I use:

      @Inject @JDBCDao("jdbc/pool") BaseJdbcDao dao;

      get WELD_001408 error like this:

      Exception while loading the app : WELD-001408 Unsatisfied dependencies for type [BaseJdbcDao] with qualifiers [@JDBCDao] at injection point [[field] @JDBCDao @Inject @Exact com.ccb.dl.common.test.JdbcTest.dao]
      org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [BaseJdbcDao] with qualifiers [@JDBCDao] at injection point [[field] @JDBCDao @Inject @Exact com.ccb.dl.common.test.JdbcTest.dao]
           at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:305)
           at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:139)
           at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:162)
           at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:385)
           at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:371)
           at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:390)
           at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:190)
           at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128)
           at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:298)
           at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
           at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
           at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:370)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1067)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1247)
           at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
           at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:465)
           at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:222)
           at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168)
           at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
           at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:234)
           at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
           at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
           at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
           at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
           at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
           at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
           at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
           at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
           at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
           at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
           at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
           at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
           at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
           at java.lang.Thread.run(Thread.java:662)
        • 1. Re: Something strange with @Producer
          yang xin Newbie
          <blockquote>
          _yang xin wrote on Jun 12, 2011 23:49:_<br/>
          my webas is glassfish3.1
          My project need a JDBCDAO util.
          so I write below:
          the qualifier:

          @Qualifier
          @Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
          @Retention(RetentionPolicy.RUNTIME)
          public @interface JDBCDao {
              @Nonbinding public String value() default "";
          }

          the Producer :
          public class DaoProductor {
              @Produces @JDBCDao
              public BaseJdbcDao getJdbcDao(InjectionPoint ip){
                  String JNDIName = ip.getAnnotated().getAnnotation(JDBCDao.class).value();
                  if( JNDIName.compareTo("")==0)
                      return null;
                  try{
                      DataSource dataSource = (javax.sql.DataSource) new javax.naming.InitialContext().lookup(JNDIName);
                      if( dataSource == null )
                          return null;
                      return new BaseJdbcDao(dataSource);
                  }catch(Exception ex){
                      ex.printStackTrace();
                      return null;
                  }
              }
          }
          and at the same project the test Code:

          @Inject @JDBCDao("jdbc/pool") BaseJdbcDao dao;

          works well


          SO I package the Qualifier,Produces,and daoutil into a jar file,
          my real project import the jar
          when I use:

          @Inject @JDBCDao("jdbc/pool") BaseJdbcDao dao;

          get WELD_001408 error like this:

          Exception while loading the app : WELD-001408 Unsatisfied dependencies for type [BaseJdbcDao] with qualifiers [@JDBCDao] at injection point [[field] @JDBCDao @Inject @Exact com.ccb.dl.common.test.JdbcTest.dao]
          org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [BaseJdbcDao] with qualifiers [@JDBCDao] at injection point [[field] @JDBCDao @Inject @Exact com.ccb.dl.common.test.JdbcTest.dao]
                  at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:305)
                  at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:139)
                  at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:162)
                  at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:385)
                  at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:371)
                  at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:390)
                  at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:190)
                  at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128)
                  at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:298)
                  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
                  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
                  at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:370)
                  at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355)
                  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
                  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1067)
                  at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
                  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1247)
                  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
                  at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:465)
                  at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:222)
                  at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168)
                  at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
                  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:234)
                  at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
                  at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
                  at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
                  at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
                  at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
                  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
                  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
                  at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
                  at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
                  at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
                  at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
                  at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
                  at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
                  at java.lang.Thread.run(Thread.java:662)

          </blockquote>

          Click HELP for text formatting instructions. Then edit this text and check the preview.