admin管理员组文章数量:1335219
情景:
新增了一个组织岗位service类,直接使用没啥问题。 但是组织类对接外部接口,有重写。启动就报错了
org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'orgServicePortalImpl': Bean with name 'orgServicePortalImpl'
has been injected into other beans [userServiceImpl,positionServiceImpl] in its raw version as part of a circular reference,
but has eventually been wrapped.
This means that said other beans do not use the final version of the bean.
This is often the result of over-eager type matching -
consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off,
for example.
大概的意思是循环依赖了。
再看了下关系:
岗位是挂组织的: PositionServiceImpl 有调用 OrgServiceImpl
组织里面有查询人员: OrgServiceImpl 有调用 UserServiceImpl
人员是查组织岗位的: UserServiceImpl 有调用 PositionServiceImpl
这样就变成循环依赖了。而且OrgServiceImpl 里面还有@Async 的使用。
处理:
处理方式一:
使用延迟加载:@Lazy的使用
@Resource
@Lazy
private IUserService userService;
处理方式二:
把循环依赖断了。因为是加了岗位才引起,再这里把循环依赖断了。
去掉 岗位里面组织类的直接引用。
@Resource
private IOrgService orgService;
改成:使用的时候,再去获取bean的方式去获取
SpringUtils.getBean(OrgServiceImpl.class)
总结:
碰到循环依赖的,把类之间的关系理清楚,看看哪些是相互引用了,把循环引用给断了。这样是比较好的
本文标签: eagerresultTypegetBeanNamesForTypematching
版权声明:本文标题:This is often the result of over-eager type matching - consider using ‘getBeanNamesForType‘ 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1738332980a2076390.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论