记一次服务启动时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;

原文地址:https://www.cnblogs.com/zjhgx/p/12158698.html

时间: 2024-10-09 11:22:52

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

服务启动时log4j提示Could not bind factory to JNDI

服务启动时log4j提示 WARN SessionFactoryObjectFactory:121 - Could not bind factory to JNDI javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  j

JavaWeb 服务启动时,在后台老板启动加载一个线程

avaWeb 服务启动时,在后台启动加载一个线程JavaWeb 服务启动时,在后台启动加载一个线程. 目前,我所掌握的一共有两种方法,第一种是监听(Listener),第二种是配置随项目启动而启动的Servlet. 下面对这两种方法做一简单的介绍,(Mark一下,防止以后急用又忘记了): 监听(Listener) 首先,我们创建一个监听的类,继承ServletContextListener,如下: 源码复制打印    package com.wxp.thread;    import javax

JavaWeb服务启动时,在后台启动加载一个线程进行Socket监听端口

最近,做一个项目,需要做一个web服务器,该服务器要与Android端和GPRS模块互相通信.考虑Android端与服务器端用Http通信,GPRS模块与服务器用Tcp通信.因此需要在Web服务器启动的时候启动加载一个线程负责Tcp端口的监听. search了一些方法,从中挑选了两个在此记录一下: 方法一:监听(Listener) 我们创建一个监听类,继承自ServletContextListener,代码如下: 1 package will; 2 3 4 import java.io.IOEx

SSH 服务启动时出现如下错误:fatal: Cannot bind any address

注意:本文相关配置及说明已在 CentOS 6.5 64 位操作系统中进行过测试.其它类型及版本操作系统配置可能有所差异,具体情况请参阅相应操作系统官方文档. 问题描述 云服务器 ECS (Elastic Compute Server) Linux 服务器启动 SSH 服务时,命令行或 secure日志出现类似如下错误信息: FAILED. fatal: Cannot bind any address. address family must be specified before Listen

一、   Spring启动时加载和初始化bean概述

Spring Context继承关系 ClassPathXmlApplicationContext->AbstractXmlApplicationContext->AbstractRefreshableConfigApplicationContext->AbstractRefreshableApplicationContext ->AbstractApplicationContext 而AbstractRefreshableApplicationContext 包含DefaultL

web服务启动spring自己主动运行ApplicationListener的使用方法

我们知道.一般来说一个项目启动时须要载入或者运行一些特殊的任务来初始化系统.通常的做法就是用servlet去初始化.可是servlet在使用spring bean时不能直接注入,还须要在web.xml配置.比較麻烦.今天介绍一下使用spring启动初始化的方法.事实上非常easy,仅仅需两步就能够了. 实现ApplicationListener接口: public class Init implements ApplicationListener<ContextRefreshedEvent>{

web服务启动spring自动执行ApplicationListener的用法

我们知道,一般来说一个项目启动时需要加载或者执行一些特殊的任务来初始化系统,通常的做法就是用servlet去初始化,但是servlet在使用spring bean时不能直接注入,还需要在web.xml配置,比较麻烦.今天介绍一下使用spring启动初始化的方法.其实很简单,只需两步就可以了. 实现ApplicationListener接口: public class Init implements ApplicationListener<ContextRefreshedEvent>{ @Ove

Dubbo_异常_Service启动时默认将方法注册到内网IP

一.背景 一般Dubbo服务都是通过内网调用,Dubbo服务启动时默认会将服务注册到内网IP,消费端就无法从外网访问. 二.解决过程 1.Linux的hosts中设置外网IP a) 通过hostname命令得到机器名 b) 通过vim /etc/hosts设置机器名对应的外网IP 127.0.0.1  localhost  localhost.localdomain 外网IP VM_31_182_centos (这里VM_31_182_centos为主机名,默认在第一行,需要移到第二行外网IP后

Tomcat启动时自动加载Servlet

1.想做一个服务启动时自动启动一不停止的获取订阅功能 2.之前是做一个Jsp页面请求servlet来触发方法 3.现在实现Tomcat启动时自动加载Servlet 1.Tomcat中启动Servlet时,只需要在Servlet所在的工程的配置文件web.xml中写成如下即可 <!-- 自动启动订阅接口 --> <servlet> <servlet-name>TimeServlet</servlet-name> <servlet-class>ser