记一次服务启动时bean注入时 Requested bean is currently in creation的问题

发现测试服务器一台muc启动失败,另一台是好的,本地也没问题,报错信息如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mucAccountLoginController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration': Unsatisfied dependency expressed through field 'configurers'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'pcAuthorizationServerConfig': Unsatisfied dependency expressed through field 'authenticationManager'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'formAuthenticationConfig'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'formAuthenticationConfig' defined in URL [jar:file:/home/rockysaas/muc/rockysaas-provider-muc.jar!/BOOT-INF/lib/rockysaas-security-core-1.0.jar!/com/rockysaas/security/core/authentication/FormAuthenticationConfig.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pcAuthenticationSuccessHandler': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'defaultAuthorizationServerTokenServices': Requested bean is currently in creation: Is there an unresolvable circular reference?

原因是原先有

复制代码
public class PcAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    @Resource
    private ObjectMapper objectMapper;

    @Resource
    private ClientDetailsService clientDetailsService;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Resource
    private MucAccountService mucAccountService;

    @Resource
    private MucPlatformMapper mucPlatformMapper;

    @Resource
    private AuthorizationServerTokenServices authorizationServerTokenServices;
复制代码

后来mucAccountLoginController加了段代码

复制代码

@RestController

public class MucAccountLoginController extends BaseController {

    @Resource
    private MucLoginService mucLoginService;
    @Resource
    private MucAccountTokenService mucUserTokenService;
    @Resource
    private ClientDetailsService clientDetailsService;
    @Autowired
    private PasswordEncoder passwordEncoder;

    @Resource
    private MdcApplicationFeignApi mdcApplicationFeignApi;

    @Resource
    private AuthorizationServerTokenServices authorizationServerTokenServices;
复制代码

原先只有一个AuthorizationServerTokenServices需要注入,现在变成两个,如果同时发生注入的时候就会报错。在其中一个要注入的类上上加上@Lazy就好了

复制代码
@RestController
@RequestMapping(value = "", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(tags = "Web - 账号登录相关", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class MucAccountLoginController extends BaseController {

    @Resource
    private MucLoginService mucLoginService;
    @Resource
    private MucAccountTokenService mucUserTokenService;
    @Resource
    private ClientDetailsService clientDetailsService;
    @Autowired
    private PasswordEncoder passwordEncoder;

    @Resource
    private MdcApplicationFeignApi mdcApplicationFeignApi;

    @Resource
    @Lazy
    private AuthorizationServerTokenServices authorizationServerTokenServices;
复制代码

 

posted @   zjhgx  阅读(8604)  评论(1编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示