0
votes

I am working on SpringBoot with Spring Integration project. While upgrading my application, i am getting following error(only on pivotal cloud and not local) -

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cloudDataBaseConfiguration': Unsatisfied dependency expressed through field 'cloud': Error creating bean with name 'cloudMultiHttpSecurityConfig': Unsatisfied dependency expressed through field 'ldapProvider': Error creating bean with name 'ldapProvider' defined in class path resource [com/fidintl/bs/addcash/config/CloudMultiHttpSecurityConfig.class]: Unsatisfied dependency expressed through method 'ldapProvider' parameter 0: Error creating bean with name 'iamClient' defined in class path resource [com/fidintl/bs/addcash/config/CloudMultiHttpSecurityConfig.class]: Unsatisfied dependency expressed through method 'iamClient' parameter 0: Error creating bean with name 'cloud': Requested bean is currently in creation: Is there an unresolvable circular reference?; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'cloud': Requested bean is currently in creation: Is there an unresolvable circular reference?; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'iamClient' defined in class path resource [com/fidintl/bs/addcash/config/CloudMultiHttpSecurityConfig.class]: Unsatisfied dependency expressed through method 'iamClient' parameter 0: Error creating bean with name 'cloud': Requested bean is currently in creation: Is there an unresolvable circular reference?; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'cloud': Requested bean is currently in creation: Is there an unresolvable circular reference?; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ldapProvider' defined in class path resource [com/fidintl/bs/addcash/config/CloudMultiHttpSecurityConfig.class]: Unsatisfied dependency expressed through method 'ldapProvider' parameter 0: Error creating bean with name 'iamClient' defined in class path resource [com/fidintl/bs/addcash/config/CloudMultiHttpSecurityConfig.class]: Unsatisfied dependency expressed through method 'iamClient' parameter 0: Error creating bean with name 'cloud': Requested bean is currently in creation: Is there an unresolvable circular reference?; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'cloud': Requested bean is currently in creation: Is there an unresolvable circular reference?;

My Configuration class -

    @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>

This issue doesn't come in local only when i push it to pivotal cloud.

1

1 Answers

3
votes

Can you try doing it this way? Cloud dependency is accessed directly through the cloud() method.

@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"));
    }

}