问题
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 < T >, 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