0

我有一个完善的 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应该找到这个类。

对此的任何帮助将不胜感激。

4

1 回答 1

1

除了我工作的最初文章之外,我还查看了多个文档来源。似乎没有人提到您不能自己加入* 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=[my region]cloud.aws.stack.auto=false。也不是很喜欢 Spring Boot。如果您不在 EC2 实例上,则必须指定 AWS 区域是有道理的,但如果我不使用 CloudFormation,则不必考虑它。Spring Cloud 文档至少在这些方面更清楚:https ://cloud.spring.io/spring-cloud-aws/1.2.x/#_configuring_region和https://cloud.spring.io/spring-cloud-aws /1.2.x/#_cloudformation_configuration_in_spring_boot

于 2019-03-01T22:36:31.350 回答