Quarkus 不以编程方式选择 bean

2024-06-02

我试图以编程方式选择 bean,但 quarkus 不会注入 bean 并引发异常。不支持吗?

public enum ReportType {
    ONE,
    TWO
}
@Qualifier
@Retention(RUNTIME)
@Target({METHOD, PARAMETER, FIELD, TYPE})
@Documented
public @interface Report {

    ReportType value();

    public static final class Literal extends AnnotationLiteral<Report> implements Report {

        private final ReportType value;

        public static Literal of(ReportType value) {
            return new Literal(value);
        }

        private Literal(ReportType value) {
            this.value = value;
        }

        public ReportType value() {
            return value;
        }
    }
}
public interface CommonnInterface {
    void call();
}
@Report(value = ReportType.ONE)
public class ReportOneBusiness implements CommonnInterface {

    @Override
    public void call() {
        System.out.println("Hello");
    }
}

当我们打电话时


        CommonnInterface commonnInterface = CDI.current()
                .select(
                        CommonnInterface.class,
                        Report.Literal.of(ReportType.ONE)
                ).get();

找不到所需类型 [接口 org.business.CommonnInterface] 和限定符 [[@org.cdi.Report(value=ONE)]] 的 bean


您可能需要使用以下命令使豆子不可移除@io.quarkus.arc.Unremovable注解。

See this https://quarkus.io/guides/cdi-reference#remove_unused_beans更多细节。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Quarkus 不以编程方式选择 bean 的相关文章

随机推荐