将弹簧从3.2升级到4 - 泛型(扩展)问题 [英] Upgrading spring from 3.2 to 4 - Issue with generics (extends)
问题描述
我有以下与spring 3.2一起工作的代码,并且在spring 4.0.0.RELEASE上失败了NoSuchBeanDefinitionException.RELEASE
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();
}
}
当我在UserDao类声明中包含T扩展Cacheable时,由于泛型失败。完整的例外是
It fails due to generics when I include T extends Cacheable in the UserDao class declaration. The complete exception is
NoSuchBeanDefinitionException:找不到依赖关系类型为[spring.generics.UserDao]的符合条件的bean:至少有一个bean符合此选项的autowire候选依赖性依赖关系注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true),@ org.springframework.beans.factory.annotation.Qualifier(value = userdao)}
"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)}"
如果声明只是UserDao& lt&T& gt,它一切正常。
If the declaration is just UserDao < T >, it all works.
任何意见/输入应该是什么修正?
Any comments/inputs on what should be the fix?
推荐答案
这个问题在春季4.0.1中解决了
This issue was resolved in spring 4.0.1
这篇关于将弹簧从3.2升级到4 - 泛型(扩展)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!