UnsatisfiedDependencyException NoSuchBeanDefinitionException

本文分析了在Spring MVC框架中出现的依赖注入错误,详细解释了UnsatisfiedDependencyException和NoSuchBeanDefinitionException异常的原因,并提供了排查问题的具体步骤。

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

2018-01-06 15:09:14,361 WARN [org.springframework.web.context.support.XmlWebApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'blogController': Unsatisfied dependency expressed through field 'categoryService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ssm.blog.service.CategoryService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ssm.blog.service.CategoryService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

上面这段异常说创建blogController的时候失败了,UnsatisfiedDependencyException是依赖不满足抛出的异常,因为我在Controller中注入了categoryService。接着NoSuchBeanDefinitionException表示没有这样一个bean,也就是说我的categoryService没有生成bean。

遇到这种情况,要检查一下以下配置:

1) service接口实现类上有没有加@Service注解,注解是不是引用的spring的类?不要导错包

2) 接口有没有写实现类,实现类是实现的对应接口么?比如CategoryServiceImpl implementsCategoryDAO 一不小心根据自动提示,本来应该实现CategoryService,结果实现了CategoryDAO

3) 有没有扫描Service所在的包

<!-- 启动自动扫描 -->
    <context:component-scan base-package="com.ssm.blog.*">
        <!-- 制定扫包规则 ,不扫描@Controller注解的JAVA类 -->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
注意这段配置要加在spring父容器中而不是springMVC子容器。因为父容器无法访问自容器的对象。



Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ODataConnectorImpl': Unsatisfied dependency expressed through field 'messages'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'weibaobiaoMessages': Unsatisfied dependency expressed through field 'securityService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'amsSecurityService': Unsatisfied dependency expressed through field 'securityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in class path resource [security-service.xml]: Cannot resolve reference to bean 'amsAuthorizationRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'amsAuthorizationRealm': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'customerService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerServiceImpl': Unsatisfied dependency expressed through field 'metadataService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'defaultMetadataServiceImpl': Unsatisfied dependency expressed through field 'zxtbTask'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'zxtbTask': Unsatisfied dependency expressed through field 'redisDistributeLock'; nested exception is org.springframework.beans.f
07-09
2025-03-27 15:47:51.709 ERROR 24032 - [restartedMain] [o.s.b.web.embedded.tomcat.TomcatStarter,onStartup,61] : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'registration' defined in class path resource [com/cloudweb/oa/security/BeanConfig.class]: Unsatisfied dependency expressed through method 'registration' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jwtFilter': Unsatisfied dependency expressed through field 'jwtUtil'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jwtUtil': Unsatisfied dependency expressed through field 'userCache'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userCache': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userGroupService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'groupServiceImpl': Unsatisfied dependency expressed through field 'departmentService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'departmentServiceImpl': Unsatisfied dependency expressed through field 'deptUserService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptUserServiceImpl': Unsatisfied dependency expressed through field 'userSetupService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userSetupServiceImpl': Unsatisfied dependency expressed through field 'roleService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleServiceImpl': Unsatisfied dependency expressed through field 'rolePrivService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rolePrivServiceImpl': Unsatisfied dependency expressed through field 'userOfRoleService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userOfRoleServiceImpl': Unsatisfied dependency expressed through field 'syncUtil'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.cloudweb.oa.api.ISyncUtil' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
03-28
分析报错:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisSubscribeListener': Unsatisfied dependency expressed through field 'alarmListener'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alarmListener': Unsatisfied dependency expressed through field 'alarmTask'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alarmTask': Unsatisfied dependency expressed through field 'alarmReceiver'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alarmReceiver': Unsatisfied dependency expressed through field 'eventAlarmLogInsertTask'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eventAlarmLogInsertTask': Unsatisfied dependency expressed through field 'eventLogAlarmService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eventLogAlarmService': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eventLogAlarmMapper' defined in URL [jar:file:/opt/evo/evo-common/evo-event/evo-event.jar!/com/dahua/evo/event/business/mapper1/EventLogAlarmMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shardingDataSource' defined in class path resource [com/dahua/evo/event/config/DataSourceConfig1.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'shardingDataSource' threw exception; nested exception is
最新发布
08-15
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

专治八阿哥的孟老师

您的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值