将“ spring-cloud-starter-aws”入门包添加到Spring Boot应用时,FileNotFoundException

时间:2019-03-01 18:04:58

标签: java spring spring-boot spring-cloud spring-cloud-aws

我有一个完善的Spring Boot服务器应用程序。我正在阅读一篇文章,将Spring配置为将指标发送到AWS Cloudwatch。

当我包含启动程序包 spring-cloud-starter-aws 时,我遇到了运行时异常。谁能告诉我为什么会收到此异常以及如何解决该问题?

这是例外,两种摘要形式:

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

和长格式:

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

我使用IntelliJ,已经在“外部库”列表中查找,并且发现了该异常所抱怨的类。 IntelliJ对代码进行反编译,我可以看到它是一个包含公共AbstractRegistrar内部类的公共类。看来Spring应该找到此类。

任何帮助,将不胜感激。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

除了我正在研究的第一篇文章之外,我还浏览了多个文档来源。似乎没有人提到您不能只自己加入 * spring-cloud-starter-aws * 。我不确定其他模块对我的影响程度如何,但是我在maven中央存储库中找到了这个模块,并将其添加到我的项目中解决了上述问题:

spring-cloud-starter-aws-jdbc

也许我早该想到了,但是我认为Spring Boot的整个想法是通过约定进行配置,这意味着您总是可以从入门者那里获得一些东西。我没有使用JDBC,所以为什么需要包括它?如果未提供所需功能,则应仅提供该功能。这是第一次使用Spring Boot来包含启动程序,这要求我包括另一个模块以避免运行时异常。哦,很好。

更新:我在Spring Cloud文档中发现了更多文档,但是仍然很粗略。文档说

  

其他依赖项,以启用消息传递等特定功能   和JDBC必须添加。 Spring Cloud AWS仅配置   Spring Boot应用程序的类路径中可用的类

这具有误导性。无论是否要“启用特定功能”,都必须添加这些额外的依赖项……期限……

顺便说一句,一旦我添加了这个额外的依赖关系,我并没有完全摆脱困境。我还有另外两个例外,其中涉及要解决的配置问题。我必须定义属性 loud.aws.region.static = [我的区域] cloud.aws.stack.auto = false 。还不是很像Spring Boot那样。如果您不在EC2实例上,则必须指定AWS区域,但如果我不使用CloudFormation,则不必考虑它。 Spring Cloud文档至少在以下几点上更加清晰:https://cloud.spring.io/spring-cloud-aws/1.2.x/#_configuring_regionhttps://cloud.spring.io/spring-cloud-aws/1.2.x/#_cloudformation_configuration_in_spring_boot