Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

stackResourceRegistryFactoryBean returns null value #496

Closed
reypader opened this issue Oct 3, 2019 · 4 comments
Closed

stackResourceRegistryFactoryBean returns null value #496

reypader opened this issue Oct 3, 2019 · 4 comments
Assignees
Labels
component: core An issue related to core functionality - credentials, region resolution status: in-progress An issue that being worked on type: bug A general bug
Milestone

Comments

@reypader
Copy link

reypader commented Oct 3, 2019

Encountering a problem with starting an application using spring-cloud-starter-aws:2.1.0.RELEASE with cloud.aws.stack.auto = false. The application encounters the following error:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stackResourceRegistryFactoryBean' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Initialization of bean failed; nested exception is java.lang.ClassCastException: org.springframework.beans.factory.support.NullBean cannot be cast to org.springframework.beans.factory.FactoryBean

This is likely due to org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration.stackResourceRegistryFactoryBean() returning null.

@Bean
    @ConditionalOnMissingBean(StackResourceRegistry.class)
    public StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean(AmazonCloudFormation amazonCloudFormation) {

        if (StringUtils.hasText(environment.getProperty("cloud.aws.stack.name"))) {
            return new StackResourceRegistryFactoryBean(amazonCloudFormation, new StaticStackNameProvider(this.environment.getProperty("cloud.aws.stack.name")));
        }

        if (environment.getProperty("cloud.aws.stack.auto") == null || "true".equalsIgnoreCase(environment.getProperty("cloud.aws.stack.auto"))) {
            return new StackResourceRegistryFactoryBean(amazonCloudFormation, new AutoDetectingStackNameProvider(amazonCloudFormation, this.amazonEC2));
        }

        return null;
    }

Should this be changed to use @ConditionalOnProperty("cloud.aws.stack.name") and @ConditionalOnProperty("cloud.aws.stack.auto") ?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 3, 2019
@JanGroot
Copy link

same issue in my project.

@maciejwalkowiak maciejwalkowiak added the component: core An issue related to core functionality - credentials, region resolution label May 29, 2020
@maciejwalkowiak
Copy link
Contributor

I am not able to reproduce it using 2.2.1 version. Could you please provide complete sample as a github repository that reproduces this issue?

@maciejwalkowiak maciejwalkowiak added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels May 29, 2020
@adannunez
Copy link

Running into the same issue. Just adding some more info that might be help troubleshoot.

I'm seeing the issue arise when beanFactory.isSingleton("stackResourceRegistryFactoryBean") is called and StackResourceRegistryFactoryBean is null due to the bean registration from the original post. In my case, the isSingleton() call is being made from a BeanPostProcessor provided by Axon.

Not sure if this means the responsibility falls under spring-cloud-aws, another Spring team, or Axon. Hopefully someone here can provide a bit more direction.

Caused by: java.lang.ClassCastException: class org.springframework.beans.factory.support.NullBean cannot be cast to class org.springframework.beans.factory.FactoryBean (org.springframework.beans.factory.support.NullBean and org.springframework.beans.factory.FactoryBean are in unnamed module of loader 'app')
	at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:441) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.axonframework.spring.config.AbstractAnnotationHandlerBeanPostProcessor.postProcessAfterInitialization(AbstractAnnotationHandlerBeanPostProcessor.java:73) ~[axon-spring-4.3.3.jar:4.3.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]

@maciejwalkowiak
Copy link
Contributor

I think @reypader suggestion is valid:

@ConditionalOnProperty("cloud.aws.stack.name") and @ConditionalOnProperty("cloud.aws.stack.auto") with havingValue=true and matchIfMissing=true should do the job. PRs welcome!

@maciejwalkowiak maciejwalkowiak added help wanted type: bug A general bug status: in-progress An issue that being worked on and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 1, 2020
@maciejwalkowiak maciejwalkowiak self-assigned this Jun 3, 2020
@maciejwalkowiak maciejwalkowiak added this to the 2.2.3 milestone Jun 7, 2020
maciejwalkowiak added a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak added a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak added a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak added a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component: core An issue related to core functionality - credentials, region resolution status: in-progress An issue that being worked on type: bug A general bug
Development

No branches or pull requests

5 participants