簡體   English   中英

Springboot Gradle 插件不適用於 Eclipse

[英]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。

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

Gradle 的 Eclipse 支持允許您配置在同步或構建項目時應該運行的任務。 它需要 Gradle 5.4 或更高版本和 Buildship(提供 Gradle 支持的 Eclipse 插件)3.1 或更高版本。

您可以通過將以下內容添加到build.gradle來配置bootBuildInfo以在 Eclipse 構建項目時運行:

eclipse {
    autoBuildTasks bootBuildInfo
}

您可以在此博客文章中了解有關該功能的更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM