2 Replies Latest reply on Feb 20, 2010 6:47 PM by alin.heyoulin.qq.com

    Injection of qualified bean to unqualified injectino point fails

    wujek
      Hi,

      I have a qualifier:

      @Qualifier
      @Inherited
      @Target( { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
      @Retention(RetentionPolicy.RUNTIME)
      public @interface MyQualifier {}

      and beans:

      public interface Injectable {}

      @MyQualifier
      public class QualifiedInjectable implements Injectable {}

      public class Tester {

          @Inject
          // @MyQualifier
          private Injectable injected;
      }

      My main class is this:

      public class WeldStart {

          public static void main(String[] args) {
              new StartMain(args).go();
          }
      }

      What happens is that I get:
      org.jboss.weld.exceptions.DeploymentException: WELD-001408 Injection point has unsatisfied dependencies.  Injection point:  field com.test.Tester.injected;  Qualifiers:  [@javax.enterprise.inject.Default()]

      When I uncomment the qualifier in Tester (see above) it works fine.

      I thought that I can inject qualified beans into unqualified injection points? The type is fine, and there exists only one implementation of the given interface, and I though the specs said such injection should be possible? The way I understand it is that the injection point type is kind of 'broader' (by not specifying the qualifier) that the bean (uses a qualifier), so such injection should be fine as long there are no ambiguities? The other way round should not work.

      What am I doing wrong here?

      I am using weld-code-1.0.1-CR2 and weld-se-1.0.1-CR2. The same issue exists for weld-core-1.0.0 and weld-se-1.0.0-CR2.

      Best regards,
      Wujek