In my project, I have the following repository structure:
public interface IRepository<T> { ... }
public abstract class AbstractRepository<T> implements IRepository<T> { ... }
@Repository
public class ARepository extends AbstractRepository<A>
implements IRepository<A> { ... }
@Repository
public class BRepository extends AbstractRepository<B>
implements IRepository<B> { ... }
@Repository
public class CRepository extends AbstractRepository<C>
implements IRepository<C> { ... }
Now I would like to add them to the appropriate services as follows:
public class MyServiceImpl implements MyService {
@Autowire
IRepository<A> arepository;
...
}
It compiles fine, but when I start the Spring context, I get the following error No qualifying bean of type 'some.package.IRepository<?>' available: expected single matching bean but found 3: aRepository, bRepository, cRepository
.
As far as I know, injection in Spring 4 (4.3.13.RELEASE used in my project) should handle this situation well, using generic types as a form of qualifier. Unfortunately, this does not work for me. Should I change some configurations? I searched a bit for this topic, but did not find anything useful. I ended up using names for my beans annotation and @Qualifier
, but with this solution, I'm still implementation dependent.
Has anyone had similar problems and managed to solve them?
@Edit
, , - , , (CTW) ajc
.