所以我在Spring 3.2中有很多泛型,理想情况下我的架构看起来像这样.
class GenericDao<T>{}
class GenericService<T, T_DAO extends GenericDao<T>>
{
// FAILS
@Autowired
T_DAO;
}
@Component
class Foo{}
@Repository
class FooDao extends GenericDao<Foo>{}
@Service
FooService extends GenericService<Foo, FooDao>{}
Run Code Online (Sandbox Code Playgroud)
遗憾的是,对于泛型的多个实现,自动装配会引发有关多个匹配bean定义的错误.我假设这是因为@Autowired类型擦除之前的进程.我找到或想出的每一个解决方案看起来都很难看,或者只是莫名其妙地拒绝工作.解决这个问题的最佳方法是什么?