首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計疑難解答

Eclipse 保存程式碼報錯:Spring Project Builder 異常解決方案

     編輯:程式設計疑難解答

錯誤現象


Errors occurred during the build.
Errors running builder 'Spring Project Builder' on project '專案名'.
org.eclipse.jdt.internal.compiler.env.IBinaryMethod.getParameterAnnotations(I)[Lorg/eclipse/jdt/internal/compiler/env/IBinaryAnnotation;

每次儲存 Java 檔案即彈出錯誤對話框,影響開發效率。

根本原因

**Eclipse JDT 編譯器與 Spring Tool Suite (STS) 版本不相容**,常見於:

  • Eclipse 升級後 STS 未同步更新
  • Maven 依賴衝突導致類別檔案格式不一致
  • `.class` 檔案損壞或殘留舊版本編譯產物

解決方案(按成功率排序)

方案一:Project → Clean(最快、最常有效)

  1. 選單列 **Project** → **Clean...**
  2. 勾選 **Clean all projects** 或僅選當前專案
  3. 勾選 **Start a build immediately**
  4. 點擊 **Clean**

原理:清除所有 `.class` 檔案與建構快取,強制全量重新編譯,修復殘留的不相容位元碼。

方案二:關閉 Spring Project Builder

  1. 專案右鍵 → **Properties** → **Builders**
  2. 取消勾選 **Spring Project Builder**
  3. Apply → OK

影響:失去 Spring 專用驗證(Bean 連線檢查、配置檔驗證),但不影響 Java 編譯與執行。適合非 Spring 專案或臨時規避。

方案三:更新/重裝 Spring Tool Suite

  1. Help → **Eclipse Marketplace** → 搜尋 **Spring Tools** → Update
  2. 或 Help → **Install New Software** → 加入 STS 更新站點:`https://spring.io/tools/sts/all`
  3. 重啟 Eclipse

方案四:Maven 依賴清理重建

  1. 專案右鍵 → **Maven** → **Update Project...** → 勾選 **Force Update of Snapshots/Releases** → OK
  2. 若無效:專案右鍵 → **Maven** → **Disable Maven Nature** → 再 **Enable Maven Nature**
  3. 或刪除 `.m2/repository` 中專案相關依賴資料夾,再 Update

方案五:切換 JRE 系統程式庫

  1. Properties → **Java Build Path** → **Libraries** 標籤
  2. 展開 **JRE System Library** → **Edit** → 選擇 **Workspace default JRE** 或具體 JDK
  3. Apply and Close

方案六:刪除 `.metadata/.plugins/org.eclipse.jdt.core` 快取


# 關閉 Eclipse 後執行
rm -rf workspace/.metadata/.plugins/org.eclipse.jdt.core/*
rm -rf workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/專案名/*

啟動 Eclipse 時加上 `-clean` 參數:`eclipse.exe -clean`

進階:錯誤堆疊深度分析


java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.env.IBinaryMethod.getParameterAnnotations(I)[Lorg/eclipse/jdt/internal.compiler.env/IBinaryAnnotation;
    at org.springframework.ide.eclipse.jdt.core.compiler.SpringAnnotationParser.parseAnnotations(SpringAnnotationParser.java:45)
    at org.springframework.ide.eclipse.jdt.core.compiler.SpringCompilerParticipant.analyze(SpringCompilerParticipant.java:120)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:900)

明確顯示 **Spring 編譯器參與者** 呼叫 **Eclipse JDT 內部 API** 失敗,證實為版本不匹配。

版本相容性對照表

Eclipse 版本相容 STS 版本Java 版本
2023-09 (4.29)4.23.0+17/21
2022-12 (4.26)4.18.0+17
2022-03 (4.23)4.14.0+11/17
2021-09 (4.21)4.11.0+11

預防措施

  • 使用 **Spring Tools 4** (基於 Language Server Protocol) 取代舊版 STS,架構解耦更穩定
  • 避免在同一 Workspace 混用多種 Eclipse 版本
  • 定期 `Project → Clean` 保持建構產物乾淨
  • 團隊統一 `.settings/` 目錄納入版控,確保 Builder 配置一致

快速驗證腳本


# 建立測試類別
public class TestBuild { public static void main(String[] args) {} }

# 保存觀察是否彈錯
# 無錯誤 → 修復成功
# 仍報錯 → 嘗試下一個方案

遇到此錯誤**首選 Project → Clean**,90% 以上情況可秒解;若頻發則升級 STS 或遷移至 Spring Tools 4 徹底根治。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved