org.springframework.beans.factory.NoSuchBeanDefinitionException

本文分析了一个关于Struts框架中出现的未处理异常问题,详细解释了错误信息,并提供了具体的解决方案,即在服务层添加@Service和@Transactional注解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Struts Problem Report

Struts has detected an unhandled exception:

Messages:
  1. No qualifying bean of type [org.jbond.cms.service.CategoryService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)}
  2. Error creating bean with name 'userAction': Injection of resource dependencies failed; nested exception isorg.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.jbond.cms.service.CategoryService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)}
  3. Unable to instantiate Action, userAction, defined for 'user_login' in namespace '/'Error creating bean with name 'userAction': Injection of resource dependencies failed; nested exception isorg.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.jbond.cms.service.CategoryService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)}
File:org/springframework/beans/factory/support/DefaultListableBeanFactory.java
Line number:1,373

Stacktraces

Unable to instantiate Action, userAction, defined for 'user_login' in namespace '/'Error creating bean with name 'userAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.jbond.cms.service.CategoryService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)}
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:316)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:397)
 
    
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.jbond.cms.service.CategoryService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)}
    org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:311)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
    org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1048)
    com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:151)
    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:171)
    com.opensymphony.xwork2.factory.DefaultActionFactory.buildAction(DefaultActionFactory.java:22)
    com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:141)
   
    
   

解决方法:

很容易看出异常

service服务层,漏写@Service、@Transactional注解了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值