【发布时间】:2020-05-25 03:59:07
【问题描述】:
问题
当我使用这个springboot插件springboot-gradle-plugin时,我的java项目没有在Eclipse中运行@
它抛出这个异常
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
[2020-02-09 15:45:27.825] - 12256 GRAVE [main] --- org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter:
***************************
APPLICATION FAILED TO START
***************************
Description:
Constructor in com.example.demo.VersionController required a bean of type 'org.springframework.boot.info.BuildProperties' that could not be found.
- Bean method 'buildProperties' in 'ProjectInfoAutoConfiguration' not loaded because @ConditionalOnResource did not find resource '${spring.info.build.location:classpath:META-INF/build-info.properties}'
有问题的示例项目
可以在此处找到包含此问题的示例存储库:springboot-gradle-plugin-issue
要查看此问题,您需要使用 Eclipse 运行此项目(我使用 eclipse 2019-09 运行它)
这个项目做什么
这个java项目使用gradle这个插件spring-boot-gradle-plugin。
该项目在控制台中打印我的 build.gradle 文件中声明的应用程序版本。
在我的 gradle.build 文件中,我包含以下几行:
springBoot {
buildInfo()
}
它所做的只是将名为“bootBuildInfo”的 Gradle 任务添加到 gradle 中,并在运行此任务时创建此文件 META-INF/build-info.properties.
在Java中,运行App时,springboot会自动加载并读取META-INF/build-info.properties来创建一个bean。
Eclipse 的问题
当我在终端中使用 gradle 构建并运行生成的 jar 文件时,所有这些都有效,但是当我通过 Eclipse 运行我的应用程序时,它不起作用。
它不会创建文件 META-INF/build-info.properties 并且当 springboot 尝试加载它时会抛出一个 bean not found 异常,因为它找不到文件。
找到解决方法
如果我执行以下操作之一,该项目将运行:
- 在 src/main/resources 文件夹下手动创建 META-INF/build-info.properties
- 在 build/resources/main 文件夹下手动创建 META-INF/build-info.properties
这些方法都是不需要的,因为它不会自动更新 build-info.properties
【问题讨论】:
标签: java eclipse spring-boot gradle buildship