I have a BaseDAO and some subClass eg:UserDaoImpl,OrderDaoImpl,now in a BaseService
public abstract class Baservice{
@Resource
private BaseDao basedao;
//something crud operate.....
}
@Service
public UserService extends BaseService{
//....
}
how to configure Spring that I can pass a real subclass to basedao
I encount a exception
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of resource fields failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.cloudking.trafficmonitor.BaseDAO] is defined: expected single matching bean but found 3: [roleDAO, userDAO
It seems you have 3 classes which extends
BaseDAOso all of them areBaseDao(IS A)You need to use
nameattribute of@ResourceFor example:
and
now if you want to inject
UserDaothen