-
Notifications
You must be signed in to change notification settings - Fork 367
stackResourceRegistryFactoryBean returns null value #496
Description
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")
?