spring boot2 - Could not autowire报错
Posted 之墨_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot2 - Could not autowire报错相关的知识,希望对你有一定的参考价值。
在测试类中导入@Autowired
注释后出现错误
今天因为尚硅谷spring boot2第11集教程中内容有一点小纰漏,导致踩到了一个坑
错误内容:
Could not autowired
运行程序后报错:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'check.springtest.NaniApplicationTest':
Unsatisfied dependency expressed through field 'person';
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'check.springtest.bean.Person' available:
expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
出错原因:
没有在person
类上面添加@Component
,它的作用是:把普通Java
对象实例化到spring
容器中
问题解决
以上是关于spring boot2 - Could not autowire报错的主要内容,如果未能解决你的问题,请参考以下文章
Spring定时任务 Could not find default TaskScheduler bean异常处理
Could not load driverClass jdbc:mysql://localhost:3306/spring
Spring Batch 解决 Could not autowire. No beans of ‘StepBuilderFactory‘ type found.
spring boot配置spring-data-jpa的时候报错CannotCreateTransactionException: Could not open JPA EntityManager