0
这里,一个类是另一个类的子类。因此,@Typed注释用于防止@Inject歧义。在CDI中使用@Typed实现子类实现的模糊依赖警告
@Dependent
public class UserScope extends Scope {}
@Dependent
@Typed(UserScopeAllowIdEquals.class) // Restrict bean type.
public class UserScopeAllowIdEquals extends UserScope {}
下列使用引起的检查中的Intellij警告:
public class A {
@Inject UserScope userScope;
}
暧昧依赖性:有所述 注入点匹配
然而多个豆,应用程序编译并运行,容器不会将其视为定义错误。它的写法有问题吗?我怀疑,如果this answer to a different question是正确的,则表明只有一个bean的bean类型包含超类。
注意:以下用法与预期的一样,不会导致Intellij检查警告。基于CDI
public class B {
@Inject UserScopeAllowIdEquals usaie;
}
加上'Default'预选赛后'UserScope'我在注入'UserScope'的时候仍然收到“Ambiguous dependency”警告。为了避免混淆fio Scope基类是抽象的,所以不会注入'Scope'。 –
@PatrickGarner你实际上需要注入抽象类,而不是具体实现 – maress
我需要为每个数据库表注入一个RoleScope,PermissionScope,AcademicYearScope,TransitionLogScope等等,一个范围类型。所有这些扩展范围。 UserScopeAllowIdEquals是这一堆中唯一的怪物,扩展了UserScope而不是Scope。 –