Spring AutoWired 服务类异常
伙计们,我很快就会生气:) 我有一个基本的 Service 类,如下所示
@Service
public class CategoryService {
@Autowired
@Qualifier("categoryDaoImp")
CategoryDaoImp categoryDaoImp;
@PostConstruct
public void asdasdas()
{
System.out.println("Yaratıldı");
}
public CategoryService()
{
System.out.println("Bla Bla");
}
}
这是我的异常..
Error creating bean with name 'categoryService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.iu.eblood.daoImp.CategoryDaoImp com.iu.eblood.serviceImp.CategoryService.categoryDaoImp; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.iu.eblood.daoImp.CategoryDaoImp] 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=categoryDaoImp)}
我确信已创建 CategoryDaoImp 类..因为我在上下文和调试模式中看到 创建的班级列表是
org.springframework.context.annotation.internalConfigurationAnnotationProcessor,
org.springframework.context.annotation.internalAutowiredAnnotationProcessor,
org.springframework.context.annotation.internalRequiredAnnotationProcessor,
org.springframework.context.annotation.internalCommonAnnotationProcessor,
org.springframework.context.annotation.internalPersistenceAnnotationProcessor,
categorydaoimp,
categoryService,
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#0,
DB2DataSource
,sessionFactory,
hibernateTemplate,
org.springframework.aop.config.internalAutoProxyCreator,
org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,
org.springframework.transaction.interceptor.TransactionInterceptor#0,
org.springframework.transaction.config.internalTransactionAdvisor,
org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,
DB2TransactionManager
I will be mad soon guys :)
I have a basic Service class look likes
@Service
public class CategoryService {
@Autowired
@Qualifier("categoryDaoImp")
CategoryDaoImp categoryDaoImp;
@PostConstruct
public void asdasdas()
{
System.out.println("Yaratıldı");
}
public CategoryService()
{
System.out.println("Bla Bla");
}
}
Here is the My Exception ..
Error creating bean with name 'categoryService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.iu.eblood.daoImp.CategoryDaoImp com.iu.eblood.serviceImp.CategoryService.categoryDaoImp; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.iu.eblood.daoImp.CategoryDaoImp] 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=categoryDaoImp)}
I am sure CategoryDaoImp class was created.. Because I saw in the context and debug mode
Created Class list are
org.springframework.context.annotation.internalConfigurationAnnotationProcessor,
org.springframework.context.annotation.internalAutowiredAnnotationProcessor,
org.springframework.context.annotation.internalRequiredAnnotationProcessor,
org.springframework.context.annotation.internalCommonAnnotationProcessor,
org.springframework.context.annotation.internalPersistenceAnnotationProcessor,
categorydaoimp,
categoryService,
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#0,
DB2DataSource
,sessionFactory,
hibernateTemplate,
org.springframework.aop.config.internalAutoProxyCreator,
org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,
org.springframework.transaction.interceptor.TransactionInterceptor#0,
org.springframework.transaction.config.internalTransactionAdvisor,
org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,
DB2TransactionManager
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 bean 名称和类型 (
CategoryDaoImp
),我猜有一个CategoryDao
接口。尝试这样做:问题是您在
CategoryDao
上放置的@Transactional
注释(再次猜测)。Looking at the bean name and type (
CategoryDaoImp
) I guess there is anCategoryDao
interface. Try with this:The problem is a
@Transactional
annotation that (guessing again) you have placed onCategoryDao
.