You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring项目引入Thymeleaf依赖编译失败,新手求助修复方法

Fixing Thymeleaf Compilation Failure in Empty Spring Boot Project

Hey there! As someone who’s stumbled through plenty of Spring Boot newbie hurdles, let’s work through this Thymeleaf compilation error you’re hitting. Since your project is totally empty (no controllers, beans, or entities added yet), the issue is almost certainly tied to dependency setup or build tool configuration—not your code. Here are the most reliable fixes to try:

1. Double-Check Your pom.xml Dependencies

First, confirm the Thymeleaf starter is correctly added in your pom.xml. Sometimes IntelliJ’s built-in Initializr has a tiny glitch here, so make sure your dependencies block looks like this (the version is managed automatically by the Spring Boot parent, so no need to specify it):

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
</dependencies>

If anything looks off, fix it, then right-click your project in IntelliJ → Maven → Reload Project to pull in the correct dependency files.

2. Clean and Refresh Your Maven Build

Corrupted cached dependencies are a super common culprit here. Run these commands in your project’s root directory (where pom.xml lives):

  • First, wipe old build artifacts: mvn clean
  • Then, force update dependencies and rebuild: mvn install -U
    The -U flag tells Maven to ignore cached snapshots and pull fresh copies from the repository. After this, try running mvn spring-boot:run again.

3. Verify IntelliJ’s Maven Configuration

Make sure IntelliJ is using a working local Maven installation instead of a potentially broken bundled version:

  • Go to File → Settings → Build, Execution, Deployment → Build Tools → Maven
  • Under "Maven home path", select your local Maven folder (e.g., ~/apache-maven-3.9.4 or C:\Program Files\Apache\maven) instead of "Bundled (Maven X.X.X)"
  • Confirm the "User settings file" points to your settings.xml (usually in ~/.m2/settings.xml or C:\Users\YourName\.m2\settings.xml)—this ensures Maven uses your repository credentials if needed.
  • Click "Apply" then "OK", then reload the Maven project as before.

4. Check JDK Version Compatibility

Spring Boot and Thymeleaf have strict JDK requirements:

  • If you’re using Spring Boot 3.x: You need JDK 17 or higher. Verify your pom.xml has <java.version>17</java.version> (or higher) and that IntelliJ is using this JDK (File → Project Structure → Project → SDK).
  • If you’re on Spring Boot 2.x: JDK 8, 11, or 16 work. Match the java.version in pom.xml to your project’s SDK.

5. Re-Create the Project (Last Resort)

If nothing else works, sometimes IntelliJ’s Initializr generates a wonky project structure. Delete your current project, then re-run the Spring Initializr in IntelliJ:

  • Stick to only selecting Web and Thymeleaf as dependencies
  • Choose a stable Spring Boot release (avoid snapshots)
  • After creating the project, immediately run mvn spring-boot:run before adding any code.

One quick note: If you see a specific error message in the terminal or IntelliJ’s build output, that can narrow things down even faster. But since you mentioned it’s a Thymeleaf-related compilation failure, these steps should cover 90% of cases.

内容的提问来源于stack exchange,提问作者munkas09

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:58:21