我有以下界面扩展第三部分界面:
public interface TypedExampleGenerator<T extends EntidadeBase> extends ExampleGenerator {}
在所有项目中,我使用CDI实例化正确类型的bean,如下所示:
public class GenericCrudBO<T extends EntidadeBase> implements CrudBO<T>{
@Inject
private Instance<CrudDAO<T>> dao;
}
public interface CrudDAO<T extends EntidadeBase> extends Serializable{...}
在大多数情况下使用通用默认实现:
@Default
public class GenericCrudDAO<T extends EntidadeBase> implements CrudDAO<T>{...}
以及具体案例的具体替代实施:
@Alternative
public class UsuarioDAO extends GenericCrudDAO<Usuario>{...}
它在我的BO和DAO层上运行良好,但是当我尝试使用TypedExampleGenerator接口时,看起来CDI无法理解&#39;我的替代豆类作为替代品。这是堆栈跟踪:
'org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [Managed Bean [class br.com.logtec.dao.example_generators.FornecedorExampleGenerator] with qualifiers [@Default @Any], Managed Bean [class br.com.logtec.dao.example_generators.FuncionarioExampleGenerator] with qualifiers [@Default @Any], Managed Bean [class br.com.logtec.dao.example_generators.UsuarioExampleGenerator] with qualifiers [@Default @Any], Managed Bean [class br.com.logtec.dao.example_generators.DocumentoExampleGenerator] with qualifiers [@Default @Any], Managed Bean [class br.com.logtec.dao.example_generators.ClienteExampleGenerator] with qualifiers [@Default @Any], Managed Bean [class br.com.logtec.dao.example_generators.GenericExampleGenerator] with qualifiers [@Default @Any], Managed Bean [class br.com.logtec.dao.example_generators.ContadorExampleGenerator] with qualifiers [@Default @Any]]
有两个实现示例,一个是通用的,一个是特定的:
@Default
public class GenericExampleGenerator implements TypedExampleGenerator<EntidadeBase>{...}
@Alternative
public class UsuarioExampleGenerator implements TypedExampleGenerator<Usuario>{...}
备选方案在我的beans.xml中声明,如您所见:
<class>br.com.logtec.dao.example_generators.ContadorExampleGenerator</class>
<class>br.com.logtec.dao.example_generators.FornecedorExampleGenerator</class>
<class>br.com.logtec.dao.example_generators.FuncionarioExampleGenerator</class>
<class>br.com.logtec.dao.example_generators.UsuarioExampleGenerator</class>
<class>br.com.logtec.dao.example_generators.DocumentoExampleGenerator</class>
<class>br.com.logtec.dao.example_generators.ClienteExampleGenerator</class>
为了清楚起见,项目中的每个实体都扩展了EntidadeBase。
答案 0 :(得分:1)
我通过替换它找到了解决方案:
@Default
public class GenericExampleGenerator implements TypedExampleGenerator<EntidadeBase>{...}
用这个:
@Default
public class GenericExampleGenerator<T extends EntidadeBase> implements TypedExampleGenerator<T>{...}