Skip to content

Upgrading spring from 3.2 to 4 - Issue with generics (extends) [SPR-11382] #16009

@spring-projects-issues

Description

@spring-projects-issues

Amit opened SPR-11382 and commented

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 ```
public class UserDao<T extends Cacheable>


"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 ```
public class UserDao<T>
```, it all works.

Any comments/inputs on what should be the fix?

Affects: 4.0 GA

Reference URL: http://stackoverflow.com/questions/21473926/upgrading-spring-from-3-2-to-4-issue-with-generics-extends

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions