【发布时间】:2014-02-23 18:50:30
【问题描述】:
我有以下代码,它与 spring 3.2 一起使用,但在 spring 4.0.0.RELEASE 上出现“NoSuchBeanDefinitionException”失败
public interface Cacheable {
}
public class TimeUnit implements Cacheable {
}
@Component
public class UserDao<T extends Cacheable> {
public void performDBOperation() {
System.out.println("Executing db operation");
}
}
@Component
public class UserService {
@Autowired
private UserDao<TimeUnit> timeUnitUserDao;
public void someService() {
timeUnitUserDao.performDBOperation();
}
}
当我在 UserDao 类声明中包含 T extends Cacheable 时,由于泛型而失败。完整的例外是
“NoSuchBeanDefinitionException: 没有为依赖找到类型 [spring.generics.UserDao] 的合格 bean: 预计至少有 1 个 bean 有资格作为此依赖的自动装配候选者。依赖注释: {@org.springframework.beans.factory.annotation .Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=userdao)}"
如果声明只是 UserDao < T >,则一切正常。
关于应该修复什么的任何 cmets/输入?
【问题讨论】:
标签: spring exception generics spring-4