java - Quarkus 不会以编程方式选择 bean
问题描述
我正在尝试以编程方式选择 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();
找不到所需类型 [interface org.business.CommonnInterface] 和限定符 [[@org.cdi.Report(value=ONE)]] 的 bean
解决方案
@io.quarkus.arc.Unremovable
您可能需要使用注释使 bean 不可移除。
有关更多详细信息,请参阅此内容。
推荐阅读
- gcloud - StackDriver 过滤器适用于 UI,不适用于 gcloud
- reactjs - React 路由器不会更改视图,但会更改 url - 应用程序在 iframe 中加载
- javascript - 用于选择的jQuery动态onchange函数
- google-apps-script - 谷歌表格脚本 - 引用一行中的特定单元格
- jquery - jquery ajax spotify php bootstrap modal没有出现
- python - 高效地将复杂的 Matlab 引擎数组转换为 numpy ndarray
- node.js - 使用 cookie-session 设置用户信息
- ios - SwiftUI 电子邮件验证
- excel - 使用整个数组但使用数组中的特定元素时 VBA 下标超出范围错误
- attributeerror - AttributeError: 'function' 对象没有属性 'drop'