Upgrading spring from 3.2 to 4 - Issue with generics (extends)

霸气de小男生 提交于 2019-12-12 02:37:20

问题


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&ltT extends Cacheable&gt {


        public void performDBOperation() {
            System.out.println("Executing db operation");
        }
    }

    @Component
    public class UserService {
         @Autowired
         private UserDao&ltTimeUnit&gt 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?


回答1:


This issue was resolved in spring 4.0.1



来源:https://stackoverflow.com/questions/21473926/upgrading-spring-from-3-2-to-4-issue-with-generics-extends

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!