0

我有以下代码与 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 >,那么一切正常。

关于应该修复什么的任何评论/输入?

4

1 回答 1

0

此问题已在春季 4.0.1 中解决

于 2014-02-04T13:45:01.287 回答