Spring AutoWired 服务类异常

发布于 2024-12-18 18:36:00 字数 2140 浏览 2 评论 0原文

伙计们,我很快就会生气:) 我有一个基本的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尽揽少女心 2024-12-25 18:36:00

查看 bean 名称和类型 (CategoryDaoImp),我猜有一个 CategoryDao 接口。尝试这样做:

@Autowired
CategoryDao categoryDao;

问题是您在 CategoryDao 上放置的 @Transactional 注释(再次猜测)。

Looking at the bean name and type (CategoryDaoImp) I guess there is an CategoryDao interface. Try with this:

@Autowired
CategoryDao categoryDao;

The problem is a @Transactional annotation that (guessing again) you have placed on CategoryDao.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文