Skip to content

Weird error when injecting Named List #939

@sixcorners

Description

@sixcorners

I think the issue is that the List is really to get all beans with that type regardless of qualifier. Anyway here is a jbang reproducer. Ends up with error: no suitable method found for list(Class<String>,String). Just have to uncomment that line. If this is intended maybe there could be a better error message?

///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.avaje:avaje-inject-generator:12.+
//COMPILE_OPTIONS -proc:full
package x;

import io.avaje.inject.Bean;
import io.avaje.inject.BeanScope;
import io.avaje.inject.Factory;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.inject.Singleton;

import java.util.List;

@Factory
class MyFactory {
  static List<String> PARAMETERS;

  @Bean
  @Named("params")
  List<String> getParameters() {
    return PARAMETERS;
  }
}

@Singleton
class di_avaje {
  @Inject
//  @Named("params")
  List<String> params;

  void run() {
    System.out.println(params);
  }

  static void main(String... args) {
    MyFactory.PARAMETERS = List.of(args);
    try (var scope = BeanScope.builder().build()) {
      scope.get(di_avaje.class).run();
    }
  }
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions