1

I have a well established Spring Boot server application. I am working through an article to configure Spring to send metrics to AWS Cloudwatch.

I'm hitting a runtime exception when I include the starter package spring-cloud-starter-aws. Can anyone tell me why I'm getting this exception and what I can do to fix the problem?

Here's the exception, in both summary form:

Caused by: java.io.FileNotFoundException: class path resource [org/springframework/cloud/aws/jdbc/config/annotation/AmazonRdsInstanceConfiguration$AbstractRegistrar.class] cannot be opened because it does not exist

and long form:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.cloud.aws.autoconfigure.jdbc.AmazonRdsDatabaseAutoConfiguration]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/cloud/aws/jdbc/config/annotation/AmazonRdsInstanceConfiguration$AbstractRegistrar.class] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:599)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:302)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:589)
at org.springframework.context.annotation.ConfigurationClassParser.access$900(ConfigurationClassParser.java:108)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports$1(ConfigurationClassParser.java:808)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:804)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:774)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:185)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:691)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at com.inlet.ifserver.IfserverApplication.main(IfserverApplication.java:19)

Caused by: java.io.FileNotFoundException: class path resource [org/springframework/cloud/aws/jdbc/config/annotation/AmazonRdsInstanceConfiguration$AbstractRegistrar.class] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:51)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:88)
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:75)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81)
at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:685)
at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getSuperClass(ConfigurationClassParser.java:998)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:332)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:589)
... 20 more

I use IntelliJ, have looked in the "External Libraries" list, and have found the class this exception is complaining about. IntelliJ decompiles the code, and I can see that it is a public class that contains a public AbstractRegistrar inner class. It seems that Spring should be finding this class.

Any help with this would be greatly appreciated.

  • Can you paste your gradle or maven config ? – howie Mar 02 '19 at 01:01
  • Hi @howie. Thanks for the offer to help, but see my own answer. I figured it out. I also found a bit more documentation in the Spring Cloud docs, but it's still sketchy. The docs say "Additional dependencies to enable particular features like messaging and JDBC have to be added. Spring Cloud AWS will only configure classes that are available in the Spring Boot application’s classpath." This is misleading. These extra jars have to be added...PERIOD...regardless of if you want to "enable particular features", which I don't. – Margaret Abba Mar 02 '19 at 22:11

1 Answers1

1

I've looked through multiple documentation sources in addition to the initial article I was working from. Nobody seems to mention that you can't just drop in * spring-cloud-starter-aws* by itself. I'm not sure to what degree other modules I'm including impact this, but I found this module in the maven central repository, and adding it to my project solved the stated issue:

spring-cloud-starter-aws-jdbc

Maybe I should have thought of this sooner, but the whole idea of Spring Boot was, I thought, that configuration through convention meant you always got something from a starter by itself. I am not using JDBC, so why do I need to include this? Functionality requiring it should just not be available if this isn't provided. This is the first time using Spring Boot that including a starter has required me to include another module to avoid a runtime exception. Oh well.

UPDATE: I found a bit more documentation in the Spring Cloud docs, but it's still sketchy. The docs say

Additional dependencies to enable particular features like messaging and JDBC have to be added. Spring Cloud AWS will only configure classes that are available in the Spring Boot application’s classpath

This is misleading. These extra dependencies HAVE TO be added...PERIOD...regardless of if you want to "enable particular features", which I don't.

BTW, I wasn't completely out of the woods once I added this additional dependency. I got two other exceptions that involved configuration additions to fix. I had to define the properties loud.aws.region.static=[my region] and cloud.aws.stack.auto=false. Also not very Spring Boot like. Having to specify the AWS Region if you're not on an EC2 instance makes sense, but having to think about CloudFormation if I won't be using it does not. The Spring Cloud docs are at least clearer on these points: https://cloud.spring.io/spring-cloud-aws/1.2.x/#_configuring_region and https://cloud.spring.io/spring-cloud-aws/1.2.x/#_cloudformation_configuration_in_spring_boot

  • A final note. My IntelliJ IDE does not recognize the property **cloud.aws.stack.auto** even though specifying it works...Spring honors it. I haven't yet been able to find where that's defined. If anyone knows what package this is defined in, I'd love to know. – Margaret Abba Mar 02 '19 at 22:26