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

Eclipse启动Spring Boot项目报错:无法找到或加载主类

Eclipse运行SpringBoot项目报错:找不到主类

运行SpringBootDemoApplication时出现以下错误:

Error: Could not find or load main class com.javacourse.springBootDemo.SpringBootDemoApplication 
Caused by: java.lang.ClassNotFoundException: com.javacourse.springBootDemo.SpringBootDemoApplication

已尝试以下解决方案但均无效:

  • 右键项目→Maven→Update Project后重新运行
  • 在pom.xml中添加<start-class>属性
  • 清空并重新创建Run Configurations
  • 检查Window→Show View→Problems,无异常提示
  • 在pom.xml中添加带executions的spring-boot-maven-plugin
  • 在pom.xml的pluginManagement中配置spring-boot-maven-plugin
  • 为spring-boot-maven-plugin添加executable=true配置

相关配置与环境信息

POM.xml内容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.6.11</version>
      <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.javacourse</groupId>
  <artifactId>springBootDemo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>springBootDemo</name>
  <description>Demo project for Spring Boot</description>
  <properties>
      <java.version>11</java.version>
  </properties>
  <dependencies>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
      </dependency>

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

  <build>
      <plugins>
          <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
              <configuration>
                  <executable>true</executable>
              </configuration>
              <executions>
                  <execution>
                      <goals>
                          <goal>repackage</goal>
                      </goals>
                  </execution>
              </executions>
          </plugin>
      </plugins>
  </build>

</project>

主类代码

package com.javacourse.springBootDemo;

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication 
public class SpringBootDemoApplication {

    public static void main(String[] args) {         
        SpringApplication.run(SpringBootDemoApplication.class, args);   
    }

}

包资源管理器结构

Package Explorer

Maven与Java版本

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: C:\apache-maven-3.8.5
Java version: 11.0.16, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11.0.16

恳请各位帮忙解决该问题,谢谢!


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 14:09:21