首页 文章

Spring Boot - 创建名为'cloud'的bean时出错:请求的bean当前正在创建:是否存在无法解析的循环引用?

提问于
浏览
0

我正在使用Spring Integration项目处理SpringBoot . 升级我的应用程序时,我收到以下错误(仅限关键 Cloud 而非本地) -

在上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为'cloudDataBaseConfiguration'的bean时出错:通过字段'cloud'表示的不满意:创建名为'cloudMultiHttpSecurityConfig'的bean时出错:不满意的依赖关系通过字段'ldapProvider'表示:在类路径资源[com / fidintl / bs / addcash / config / CloudMultiHttpSecurityConfig.class]中定义名称为'ldapProvider'的bean时出错:通过方法'ldapProvider'参数表示的不满意依赖0:创建bean时出错在类路径资源中定义名称'iamClient'[com / fidintl / bs / addcash / config / CloudMultiHttpSecurityConfig.class]:通过方法'iamClient'表示的不满意依赖关系0:创建名为'cloud'的bean时出错:请求的bean当前是在创作中:是否存在无法解析的循环引用?嵌套异常是org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名为'cloud'的bean时出错:请求的bean当前正在创建:是否存在无法解析的循环引用?嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:在类路径资源[com / fidintl / bs / addcash / config / CloudMultiHttpSecurityConfig.class]中定义名称为'iamClient'的bean创建错误:通过方法'iamClient'表示不满意的依赖关系参数0:创建名为'cloud'的bean时出错:请求的bean当前正在创建:是否存在无法解析的循环引用?嵌套异常是org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名为'cloud'的bean时出错:请求的bean当前正在创建:是否存在无法解析的循环引用?嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:在类路径资源[com / fidintl / bs / addcash / config / CloudMultiHttpSecurityConfig.class]中定义名称为'ldapProvider'的bean创建错误:通过方法'ldapProvider'表示不满意的依赖关系参数0:在类路径资源[com / fidintl / bs / addcash / config / CloudMultiHttpSecurityConfig.class]中定义名称为'iamClient'的bean时出错:通过方法'iamClient'参数表示的不满意依赖0:创建名为'cloud的bean时出错':请求的bean目前正在创建:是否存在无法解析的循环引用?嵌套异常是org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名为'cloud'的bean时出错:请求的bean当前正在创建:是否存在无法解析的循环引用?

我的配置类 -

@Configuration
@EnableWebSecurity
@Order(Ordered.HIGHEST_PRECEDENCE)
@Profile("cloud")
public class CloudMultiHttpSecurityConfig extends WebSecurityConfigurerAdapter {

    private static final Logger LOGGER = LoggerFactory.getLogger(CloudMultiHttpSecurityConfig.class);
    @Autowired
    private AuthenticationProvider ldapProvider;

    @Autowired
    private Environment env;

    @Bean
    public Cloud cloud() {
        return new CloudFactory().getCloud();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(ldapProvider);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().fullyAuthenticated();
        http.httpBasic();
        http.csrf().disable();
    }

    @Bean
    public AuthenticationProvider ldapProvider(IAMClient iamClient, Cloud cloud) {
        IamLdapServiceInfo iamServiceInfo = (IamLdapServiceInfo) cloud.getServiceInfo("ldap-provider-info");
        return new AdvLdapAuthProvider(iamServiceInfo, new IAMAuthorityProvider(iamClient));
    }

    @Bean
    public IAMClient iamClient(Cloud cloud) throws Spml2Exception {
        WebServiceInfo serviceInfo = (WebServiceInfo) cloud.getServiceInfo("iam-client-info");
        IAMClient iamClient = new IAMClient(new Spml2Client(serviceInfo.getUri()), serviceInfo.getAppName(), serviceInfo.getUserName(), serviceInfo.getPassword());
        return iamClient;
    }

    @Bean
    public SonUrlService sonataServiceInfo(Cloud cloud) {
        LOGGER.info("Inside sonataServiceInfo Bean, type of serviceInfoBean :" + cloud.getServiceInfo("SonUrlService" + env.getProperty("ups_envn")).getClass());
        return (SonUrlService) cloud.getServiceInfo("SonUrlService" + env.getProperty("ups_envn"));
    }

    @Bean
    public QueueConnectionFactoryServiceInfo mqServiceInfo(Cloud cloud) {
        LOGGER.info("Inside QueueConnectionFactoryServiceInfo Bean, type of mqServiceInfo :" + cloud.getServiceInfo("QueueConnectionFactory_" + env.getProperty("ups_envn")).getClass());
        return (QueueConnectionFactoryServiceInfo) cloud.getServiceInfo("QueueConnectionFactory_" + env.getProperty("ups_envn"));
    }

    @Bean
    public QueueNamesServiceInfo queueNamesServiceInfo(Cloud cloud) {
        return (QueueNamesServiceInfo) cloud.getServiceInfo("QueueNames_" + env.getProperty("ups_envn"));
    }

}

pom.xml -

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.0.RELEASE</version>
    <relativePath />
    </parent>

仅当我将其推向关键 Cloud 时,此问题才会出现在本地 .

1 回答

  • 2

    你能尝试这样做吗?通过cloud()方法直接访问 Cloud 依赖关系 .

    @Configuration
    @EnableWebSecurity
    @Order(Ordered.HIGHEST_PRECEDENCE)
    @Profile("cloud")
    public class CloudMultiHttpSecurityConfig extends WebSecurityConfigurerAdapter {
    
        private static final Logger LOGGER = LoggerFactory.getLogger(CloudMultiHttpSecurityConfig.class);
        @Autowired
        private AuthenticationProvider ldapProvider;
    
        @Autowired
        private Environment env;
    
        @Bean
        public Cloud cloud() {
            return new CloudFactory().getCloud();
        }
    
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.authenticationProvider(ldapProvider);
        }
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().anyRequest().fullyAuthenticated();
            http.httpBasic();
            http.csrf().disable();
        }
    
        @Bean
        public AuthenticationProvider ldapProvider(IAMClient iamClient) {
            IamLdapServiceInfo iamServiceInfo = (IamLdapServiceInfo) cloud().getServiceInfo("ldap-provider-info");
            return new AdvLdapAuthProvider(iamServiceInfo, new IAMAuthorityProvider(iamClient));
        }
    
        @Bean
        public IAMClient iamClient() throws Spml2Exception {
            WebServiceInfo serviceInfo = (WebServiceInfo) cloud().getServiceInfo("iam-client-info");
            IAMClient iamClient = new IAMClient(new Spml2Client(serviceInfo.getUri()), serviceInfo.getAppName(), serviceInfo.getUserName(), serviceInfo.getPassword());
            return iamClient;
        }
    
        @Bean
        public SonUrlService sonataServiceInfo() {
            LOGGER.info("Inside sonataServiceInfo Bean, type of serviceInfoBean :" + cloud().getServiceInfo("SonUrlService" + env.getProperty("ups_envn")).getClass());
            return (SonUrlService) cloud().getServiceInfo("SonUrlService" + env.getProperty("ups_envn"));
        }
    
        @Bean
        public QueueConnectionFactoryServiceInfo mqServiceInfo() {
            LOGGER.info("Inside QueueConnectionFactoryServiceInfo Bean, type of mqServiceInfo :" + cloud().getServiceInfo("QueueConnectionFactory_" + env.getProperty("ups_envn")).getClass());
            return (QueueConnectionFactoryServiceInfo) cloud().getServiceInfo("QueueConnectionFactory_" + env.getProperty("ups_envn"));
        }
    
        @Bean
        public QueueNamesServiceInfo queueNamesServiceInfo() {
            return (QueueNamesServiceInfo) cloud().getServiceInfo("QueueNames_" + env.getProperty("ups_envn"));
        }
    
    }
    

相关问题