Pergunta

I have the below code that worked with spring 3.2 and fails with a "NoSuchBeanDefinitionException" on spring 4.0.0.RELEASE

    
    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();
         }
    }



It fails due to generics when I include T extends Cacheable in the UserDao class declaration. The complete exception is

"NoSuchBeanDefinitionException: No qualifying bean of type [spring.generics.UserDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=userdao)}"

If the declaration is just UserDao &lt T &gt, it all works.

Any comments/inputs on what should be the fix?

Foi útil?

Solução

This issue was resolved in spring 4.0.1

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top