当前位置: 首页 > 知识库问答 >
问题:

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

东门清夷
2023-03-14

我正在从事SpringBoot与Spring集成项目。升级应用程序时,我遇到以下错误(仅在pivotal cloud上,而不是本地)-

上下文初始化期间遇到异常-取消刷新尝试:org。springframework。豆。工厂未满足的依赖项异常:创建名为“cloudDataBaseConfiguration”的bean时出错:通过字段“cloud”表示未满足的依赖项:创建名为“cloudMultiHttpSecurityConfig”的bean时出错:通过字段“ldapProvider”表示未满足的依赖项:创建在类路径资源中定义的名为“ldapProvider”的bean时出错[com/fidintl/bs/addcash/config/CloudMultiHttpSecurityConfig.class]:通过方法“ldapProvider”参数0表示的未满足的依赖关系:创建在类路径资源[com/fidintl/bs/addcash/config/CloudMultiHttpSecurityConfig.class]中定义的名为“iamClient”的bean时出错:通过方法“iamClient”表示的未满足的依赖关系参数0:创建名为“cloud”的bean时出错:请求的bean当前正在创建中:是否存在无法解析的循环引用?;嵌套的异常是org。springframework。豆。工厂BeanCurrentlyIncremationException:创建名为“cloud”的bean时出错:请求的bean当前正在创建中:是否存在无法解析的循环引用?;嵌套的异常是org。springframework。豆。工厂未满足的依赖项异常:创建在类路径资源[com/fidintl/bs/addcash/config/CloudMultiHttpSecurityConfig.class]中定义的名为“iamClient”的bean时出错:通过方法“iamClient”参数0表示的未满足的依赖项:创建名为“cloud”的bean时出错:请求的bean当前正在创建中:是否存在不可解循环参考?;嵌套的异常是org。springframework。豆。工厂BeanCurrentlyIncremationException:创建名为“cloud”的bean时出错:请求的bean当前正在创建中:是否存在无法解析的循环引用?;嵌套的异常是org。springframework。豆。工厂未满足的依赖项异常:创建在类路径资源[com/fidintl/bs/addcash/config/CloudMultiHttpSecurityConfig.class]中定义的名为“ldapProvider”的bean时出错:通过方法“ldapProvider”参数0表示的未满足的依赖项:创建在类路径资源中定义的名为“iamClient”的bean时出错[com/fidintl/bs/addcash/config/CloudMultiHttpSecurityConfig.class]:通过方法“iamClient”参数0表示的未满足的依赖关系:创建名为“cloud”的bean时出错:请求的bean当前正在创建中:是否存在无法解析的循环引用?;嵌套的异常是org。springframework。豆。工厂BeanCurrentlyIncremationException:创建名为“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"));
    }

}

波姆。xml-

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

这个问题并不是只有在我把它推到pivotal cloud时才出现在本地的。

共有1个答案

楚权
2023-03-14

你能试试这样做吗?云依赖关系直接通过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"));
    }

}
 类似资料: