[英]Springboot Gradle Plugin not working with Eclipse
當我使用這個 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。
當我在終端中使用 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.