今天在工作的时候遇到一个巨坑的bug, 日志提示是这样的。

Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'userService':

Injection of resource dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'userBranchAccountService':

Injection of resource dependencies failed; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException:

No qualifying bean of type [sys.user.repository.UserRepository] found for
dependency: expected at least 1 bean which qualifies as autowire candidate for
this dependency. Dependency annotations:

{@javax.annotation.Resource(shareable=true, lookup=, name=, description=,
authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}

当时我真的是心里有各种曹尼玛在飞奔,我明明就写了userService和UserRepository    
@Autowired也是正常的写的,各种不知道原因,

最后发现是我的包名中有大写字母,没有被识别出来,在此写出,希望在以后的工作中有些按照约定俗成的写法还是用约定俗成的写法

BeanCreationException 一般情况就是一下先查看自己的配置有没有写对,@Service
@Repository@Controller之类的有没有写对,用Autowired的话,还有可能出现注入重复的问题如果还用了其他的比方说jpa有没有在主类上面写上必要的配置比方说@EnableJpaRepositories(repositoryBaseClass
= SimpleBaseRepository.class)

然后就是循环依赖的问题,反正报BeanCreationException 这个错误说明自己的容器是已经创建成功了的,就是网容器中丢东西的时候出现了意外

 

友情链接
ioDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信