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

IntelliJ创建Spring Boot项目报错:Cannot resolve symbol SpringApplication

Fixing "Cannot resolve symbol SpringApplication" in Spring Boot (IntelliJ)

Hey there! Let's work through this frustrating error you're hitting with your Spring Boot project created via IntelliJ's Spring Initializr. Since you've already tried invalidating caches and restarting, let's dive into other common fixes that usually get things back on track:

  • Verify your build tool dependencies are properly imported
    First, double-check your pom.xml (Maven) or build.gradle (Gradle) to make sure you have the core Spring Boot starter dependency. For Maven, it should look something like this:

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

    Then, in IntelliJ's right-side panel, use the Maven/Gradle tools to reload your project: click "Reload All Maven Projects" (for Maven) or "Refresh Gradle Project" (for Gradle). You can also run clean followed by compile to force dependency resolution.

  • Check your project SDK configuration
    Spring Boot has specific Java version requirements (3.x needs Java 17+, 2.x works with Java 8+). Head to File > Project Structure > Project to confirm your Project SDK and language level match what your Spring Boot version expects. Then check File > Project Structure > Modules to ensure each module uses the same SDK.

  • Enable automatic dependency importing
    Sometimes IntelliJ fails to auto-import dependencies. Go to File > Settings > Build, Execution, Deployment > Build Tools > Maven > Importing and make sure "Import Maven projects automatically" is checked (for Gradle, look in the corresponding Gradle settings). If you had to enable this, restart IntelliJ afterward.

  • Clear local dependency caches and re-download
    Corrupted local dependencies can cause this issue. For Maven, delete the org/springframework/boot folder in your local Maven repo (default path: ~/.m2/repository). For Gradle, delete the ~/.gradle/caches directory. Then go back to IntelliJ and reload your project to trigger a fresh download of dependencies.

  • Validate your project structure and imports
    Make sure your main application class (annotated with @SpringBootApplication) is in the correct base package (e.g., if your group ID is com.example, the class should be in com.example or a subpackage). Also, manually check that the import for SpringApplication is present:

    import org.springframework.boot.SpringApplication;
    

    Sometimes auto-generated code misses this import for odd reasons—adding it manually can fix the symbol resolution.

If none of these steps work, try creating a brand new Spring Initializr project and compare its configuration, dependencies, and structure to your current one. Often, this helps spot subtle issues in the original project setup.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:15:45